如何在AutoIt中访问数组,比如数组?(我将代码从c++移植到AutoIt)

时间:2022-06-01 16:43:07

Ok, gah, syntax conversion issue here...How would I do this in AutoIt?

好的,这里是语法转换问题…我要怎么做呢?

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

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

I am trying to access individual chars within a string in AutoIt and extract them. Thats's it. Thanks.

我尝试在AutoIt中的字符串中访问单个chars并提取它们。这是它。谢谢。

2 个解决方案

#1


2  

What about this:

这个:

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

#2


1  

#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, it's just as simple to copy a string. to access a piece of a string (including a character, which is still a string) you use StringMid() which is a holdover from Microsoft BASIC-80 and now Visual BASIC (and all BASICs). you can stil do

在autoit中,复制字符串同样简单。要访问一个字符串(包括一个字符,它仍然是一个字符串),您可以使用StringMid(),它是Microsoft BASIC-80的holdover,现在是Visual BASIC(以及所有基础)。你还可以做

theNewStr = theStr

or you can do it the hard way:

或者你也可以这么做:

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 concatenation in autoit. stringmid extracts a chunk of a string. it MIGHT also allow you to do the reverse: replace a chunk of a string with something else. but I would do unit testing with that. I think that works in BASIC, but not sure about autoit.

并在autoit中连接。stringmid提取一段字符串。它还可以让你做相反的事情:用别的东西替换掉一个字符串。但是我会用它来做单元测试。我认为这是基本的,但对autoit不太肯定。

#1


2  

What about this:

这个:

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

#2


1  

#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, it's just as simple to copy a string. to access a piece of a string (including a character, which is still a string) you use StringMid() which is a holdover from Microsoft BASIC-80 and now Visual BASIC (and all BASICs). you can stil do

在autoit中,复制字符串同样简单。要访问一个字符串(包括一个字符,它仍然是一个字符串),您可以使用StringMid(),它是Microsoft BASIC-80的holdover,现在是Visual BASIC(以及所有基础)。你还可以做

theNewStr = theStr

or you can do it the hard way:

或者你也可以这么做:

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 concatenation in autoit. stringmid extracts a chunk of a string. it MIGHT also allow you to do the reverse: replace a chunk of a string with something else. but I would do unit testing with that. I think that works in BASIC, but not sure about autoit.

并在autoit中连接。stringmid提取一段字符串。它还可以让你做相反的事情:用别的东西替换掉一个字符串。但是我会用它来做单元测试。我认为这是基本的,但对autoit不太肯定。