#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。