字符串中的变量

问题描述 投票:0回答:3

我有以下脚本,但没有成功执行它而没有错误。我想将一个变量放入 URL 并 ping 该 URL。

#include <Excel.au3>

$sFilePath1 = "D:\Desktop\1.xlsx"
$oExcel = _ExcelBookOpen($sFilePath1, 0)

For $i = 1 To 2 ; Loop
    Local $username = _ExcelReadcell($oExcel, $i, 1) ;Reading created Excel
    Local $iPing = Ping("http://blogsearch.google.co.in/ping?url="$username"&btnG=Submit+Blog&hl=en", 2500)

    If $iPing Then ; If a value greater than 0 was returned then display the following message.
            MsgBox(0, "STATUS", "Ping Successful", 1)
    Else
        MsgBox(0, "STATUS", "ERROR", 1)
    EndIf
Next
string variables ping autoit
3个回答
0
投票

如 Teifun2 所示,您只需在引号或双引号之间写入文本,然后在最后一个引号和变量之间放置“&”,这样:

"I am writing this between double quotes at line # " & $i_Nbr & ' with simple quotes!' 

0
投票

就像异种生物学家在对该问题的评论中已经说过的那样,这应该可以正常工作:

#include <Excel.au3>

$sFilePath1 = "D:\Desktop\1.xlsx"
$oExcel = _ExcelBookOpen($sFilePath1, 0)
For $i = 1 To 2 ;Loop
    Local $username = _ExcelReadcell($oExcel, $i, 1) ;Reading created Excel
    Local $iPing = Ping("http://blogsearch.google.co.in/ping?url="&$username&"&btnG=Submit+Blog&hl=en", 2500)

    If $iPing Then ; If a value greater than 0 was returned then display the following message.
        MsgBox(0, "STATUS", "Ping Successful" ,1)
    Else
        MsgBox(0, "STATUS", "ERROR" ,1)
    EndIf
Next

0
投票

将变量连接到字符串:

$id = 21622809
MsgBox(0, '', "http://example.com/user/" & $id & "/blah_blah_blah")

或者启用

ExpandVarStrings
选项来使用变量:

$id = 21622809
Opt("ExpandVarStrings", 1)
MsgBox(0, "", "http://example.com/user/$id$/blah_blah_blah")
© www.soinside.com 2019 - 2024. All rights reserved.