Comment puis-je accéder à une chaîne comme un tableau AutoIt? (Je suis le code de portage C ++ pour AutoIt)

StackOverflow https://stackoverflow.com/questions/4597006

  •  15-10-2019
  •  | 
  •  

Question

Ok, Gah, problème de conversion de syntaxe ici ... Comment pourrais-je faire dans AutoIt?

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

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

Je tente d'accéder à caractères individuels dans une chaîne en AutoIt et les extraire. Cest est tout. Merci.

Était-ce utile?

La solution

Qu'en est-il ceci:

$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)

Autres conseils

#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

dans AutoIt, il est tout aussi simple de copier une chaîne. d'accéder à un morceau d'une chaîne (y compris un caractère, ce qui est encore une chaîne) que vous utilisez StringMid () qui est un vestige de Microsoft BASIC-80 et maintenant Visual Basic (et toutes les bases). vous pouvez faire Stil

theNewStr = theStr

ou vous pouvez le faire à la dure:

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).

& I concaténation dans AutoIt. stringmid extrait un morceau d'une chaîne. il peut également vous permettre de faire l'inverse: remplacer un morceau d'une chaîne avec autre chose. mais je faire des tests unitaires avec cela. Je pense que les travaux de base, mais pas sûr AutoIt.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top