如何访问诸如Autoit中的数组之类的字符串? (我正在将代码从C ++移植到自动)

StackOverflow https://stackoverflow.com/questions/4597006

  •  15-10-2019
  •  | 
  •  

好的,gah,这里的语法转换问题...我该如何在自动上执行此操作?

String theStr = "Here is a string";
String theNewStr = "";

for ( int theCount = 0; theCount < theStr.Size(); theCount++ )
{
theNewStr.Append(theStr[theCount]);
}

我正在尝试在自动启动中的字符串中访问单个字符并提取它们。就是这样。谢谢。

有帮助吗?

解决方案

那这个呢:

$theStr = StringSplit("Here is a string", "") ; Create an array
$theNewStr = ""

For $i = 1 to $theStr[0] Step 1
    $theNewStr = $theNewStr & $theStr[$i]
Next
MsgBox(0, "Result", $theNewStr)

其他提示

#include <string>
std::string theStr = "Here is a string";
std::string theNewStr; 
//don't need to assign blank string, already blank on create

for (size_t theCount = 0; theCount < theStr.Size(); theCount++ )
{
    theNewStr += theStr[theCount];
}
//or you could just do 
//theNewStr=theStr;
//instead of all the above

在Autoit中,复制字符串同样简单。要访问一块字符串(包括字符,仍然是字符串),请使用StringMid(),这是Microsoft Basic-80和现在的Visual Basic(以及所有基础知识)的保留。你可以做

theNewStr = theStr

或者,您可以很难做到:

For $theCount = 1 to StringLen($theStr)
    theNewStr &= StringMid($theStr, $theCount, 1)
Next
;Arrays and strings are 1-based (well arrays some of the time unfortunately).

&是自动加入的串联。 StringMid提取一块字符串。它还可以让您进行反面:用其他东西替换一块字符串。但是我会对此进行单位测试。我认为这适用于基本,但不确定自动。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top