Come posso accedere una stringa come un array in AutoIt? (Sto porting di codice da C ++ a AutoIt)
Domanda
Ok, gah, sintassi problema di conversione qui ... Come potrei fare questo in AutoIt?
String theStr = "Here is a string";
String theNewStr = "";
for ( int theCount = 0; theCount < theStr.Size(); theCount++ )
{
theNewStr.Append(theStr[theCount]);
}
Sto cercando di accedere ai singoli caratteri all'interno di una stringa in AutoIt ed estrarli. Quello è tutto. Grazie.
Soluzione
Che dire di questo:
$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)
Altri suggerimenti
#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
in AutoIt, è altrettanto semplice per copiare una stringa. per accedere a un pezzo di una stringa (tra cui un personaggio, che è ancora una stringa) si utilizza StringMid () che è un retaggio da Microsoft BASIC-80 e ora Visual Basic (e tutte le basi). si può fare Stil
theNewStr = theStr
o si può fare nel modo più difficile:
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).
& IS concatenazione in AutoIt. stringmid estrae un pezzo di una stringa. Potrebbe anche consentire di fare il contrario: sostituire un pezzo di una stringa con qualcos'altro. ma vorrei fare test di unità con quello. Credo che le opere in BASIC, ma non sono sicuro di autoit.