如何在AutoIt中访问类似数组的字符串? (我将代码从C ++移植到AutoIt)

时间:2011-01-04 18:27:14

标签: c++ autoit

好的,gah,这里的语法转换问题......我如何在AutoIt中执行此操作?

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

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

我正在尝试访问AutoIt中字符串中的各个字符并提取它们。多数民众赞成吧。感谢。

2 个答案:

答案 0 :(得分:2)

这个怎么样:

$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)

答案 1 :(得分:1)

#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(以及所有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).

&安培;是autoit中的连接。 stringmid提取字符串的一大块。它可能也允许你做反过来:用其他东西替换一个字符串的块。但我会用那个进行单元测试。我认为这适用于BASIC,但不确定autoit。