AutoIt で配列のような文字列にアクセスするにはどうすればよいですか?(コードを C++ から AutoIt に移植しています)

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

  •  15-10-2019
  •  | 
  •  

質問

OK、ああ、ここで構文変換の問題が発生しました...AutoIt でこれを行うにはどうすればよいでしょうか?

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

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

AutoIt の文字列内の個々の文字にアクセスして抽出しようとしています。それだけです。ありがとう。

役に立ちましたか?

解決

これはどうですか:

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

他のヒント

#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 では、文字列をコピーするのと同じくらい簡単です。文字列の一部 (文字列である文字を含む) にアクセスするには、Microsoft BASIC-80 および現在の Visual BASIC (およびすべての BASIC) からの名残である StringMid() を使用します。まだできるよ

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についてはわかりません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top