如何在visual studio中的变量中引用

时间:2017-03-14 23:36:58

标签: visual-studio-2012

我在visual studio中编写代码,但我试图将“放在变量中。这是我的代码

Public Class Form1     Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)_     处理Button1.Click

    Dim sb As New System.Text.StringBuilder

    sb.AppendLine("@echo off")
    Dim i As Integer
    Randomize()
    i = (Rnd() * 5) + 1
    If i < 2 Then
        sb.AppendLine("Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "https://www.google.com"")
        ' I'm trying to put the line above with quotes in it. The quotes within the line like at ("%ProgramFiles%\Internet Explorer\iexplore.exe") must stay quotes for them to be recognized in my batch file
        sb.AppendLine("echo.")
        sb.AppendLine("echo.")
        sb.AppendLine("echo.")
        sb.AppendLine("echo WARNING!!! PROCEED WITH CAUTION")
        sb.AppendLine("ping 1.1.1.1 -w -n 1")
        sb.AppendLine("GoTo begin")
        GoTo Save
    ElseIf i >= 2 And i <= 5 Then
        Label2.Text = "2-4"
        Label3.Text = i
    Else
        Label2.Text = "5"
        Label3.Text = i
    End If
Save:
    IO.File.WriteAllText("Xx_hi_xX.bat", sb.ToString())

End Sub

End Class

先谢谢!

1 个答案:

答案 0 :(得分:1)

你可以通过在它们前面放一个反斜杠\来划定引号,这样你的命令就会变成

sb.AppendLine("Start \"\" \"%ProgramFiles%\Internet Explorer\iexplore.exe\" \"https://www.google.com\"")

或者,用chr(34)替换引号,并用&amp;

附加字符串
相关问题