¿Cómo puedo acceder a una cadena como una matriz en AutoIt? (Estoy portar código de C ++ para AutoIt)
Pregunta
Ok, gah, problema de conversión de sintaxis aquí ... ¿Cómo voy a hacer esto en AutoIt?
String theStr = "Here is a string";
String theNewStr = "";
for ( int theCount = 0; theCount < theStr.Size(); theCount++ )
{
theNewStr.Append(theStr[theCount]);
}
Estoy intentando tener acceso a caracteres individuales dentro de una cadena en AutoIt y extraerlos. Eso es todo. Gracias.
Solución
¿Qué hay de esto:
$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)
Otros consejos
#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
en autoit, es igual de fácil de copiar una cadena. para acceder a una pieza de una cadena (incluyendo un personaje, que sigue siendo una cadena) se utiliza StringMid (), que es un vestigio de Microsoft BASIC-80 y ahora Visual Basic (y todo lo básico). se puede hacer Stil
theNewStr = theStr
o puede hacerlo de la manera difícil:
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).
Y es la concatenación de autoit. stringmid extrae un trozo de una cadena. También podría permitirle hacer lo contrario: reemplazar una parte de una cadena con otra cosa. pero me gustaría hacer las pruebas unitarias con eso. Creo que las obras en BASIC, pero no está seguro acerca autoit.