Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何使一个变量等于.txt文件的多行?_String_Variables_Text Files_Autoit - Fatal编程技术网

String 如何使一个变量等于.txt文件的多行?

String 如何使一个变量等于.txt文件的多行?,string,variables,text-files,autoit,String,Variables,Text Files,Autoit,如何让一个变量在每个循环中更新其字符串值?我将文本文件的行存储在名为$trunt的变量中,然后在文本框中显示它 .txt文件: 我的自动IT脚本: $trunt始终等于字符串“dog”(pw.txt的第一行),这意味着在文本框中输入“dog”5次。我希望“狗”、“苹果”、“沙子”、“鞋子”和“帽子”都能在不同的时间单独输入到文本框中 如何使变量$trunt在每次循环迭代后等于“pw.txt”中的以下行(例如 第一次迭代$trunt=“Dog” 第二次迭代$trunt=“苹果” 第三次迭代$t

如何让一个变量在每个循环中更新其字符串值?我将文本文件的行存储在名为
$trunt
的变量中,然后在文本框中显示它

.txt文件:

我的自动IT脚本:

$trunt
始终等于字符串“dog”(pw.txt的第一行),这意味着在文本框中输入“dog”5次。我希望“狗”、“苹果”、“沙子”、“鞋子”和“帽子”都能在不同的时间单独输入到文本框中

如何使变量
$trunt
在每次循环迭代后等于“pw.txt”中的以下行(例如

  • 第一次迭代
    $trunt
    =“Dog”
  • 第二次迭代
    $trunt
    =“苹果”
  • 第三次迭代
    $trunt
    =“Sand”等)

  • 文本行是示例,可能会更改。

    您需要使用文件句柄。此时,您正在打开文件,读取文件并在循环的每个迭代中关闭它。通过使用文件句柄,文件保持打开状态并读取下一行

    e、 g


    我会将整个文件读入数组,而不是读取每一行:

    $aPW = FileReadToArray("pw.txt")
    For $attempt In $aPW
        MsgBox(0, "test", $attempt)
    Next
    
    好处:您不必事先知道文件中有多少行,而且速度更快,因为您只需访问一次文件


    注意:一个数组的最大元素数为16777216(),因此,当您的文件大于1670万行时,Richards答案是您的选择,尽管速度有缺点。

    请将代码和文件内容粘贴在此处,而不是代码图像。
    $aPW = FileReadToArray("pw.txt")
    For $attempt In $aPW
        MsgBox(0, "test", $attempt)
    Next