0

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

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

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

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

4

2 回答 2

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)
于 2011-01-04T18:57:36.220 回答
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。

于 2014-03-18T01:37:18.707 回答