簡體   English   中英

如何在AutoIt中訪問類似於數組的字符串? (我正在將代碼從C ++移植到AutoIt)

[英]How can I access a string like an array in AutoIt? (I'm porting code from C++ to AutoIt)

好吧,啊,這里的語法轉換問題...我將如何在AutoIt中做到這一點?

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

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

我試圖在AutoIt中訪問字符串中的單個字符並提取它們。 就是這樣。 謝謝。

那這個呢:

$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(以及所有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提取字符串的一部分。 它可能還允許您進行相反操作:用其他內容替換字符串的一部分。 但我會做單元測試。 我認為這可以在BASIC中使用,但不能肯定autoit。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM