如何在 AutoIt 中访问像数组一样的字符串? (我正在将代码从 C++ 移植到 AutoIt)

发布于 2024-10-10 00:46:53 字数 284 浏览 0 评论 0原文

好吧,啊,语法转换问题在这里...我该如何在 AutoIt 中做到这一点?

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

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

我正在尝试访问 AutoIt 中字符串中的各个字符并提取它们。就是这样。谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城孤痞 2024-10-17 00:46:53

这个怎么样:

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

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)
迷荒 2024-10-17 00:46:53
#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).

&是 autoit 中的串联。 stringmid 提取字符串的一块。它也可能允许您执行相反的操作:用其他内容替换字符串的一部分。但我会用它来做单元测试。我认为这在 BASIC 中有效,但不确定 autoit 是否有效。

#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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文