如何在 visual studio 中的变量内加上引号

How to have quotes inside of a variable in visual studio

我正在 visual studio 中编写代码,但我试图将 " 放在一个变量中。这是我的代码:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles 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

您可以通过在引号前面加上反斜杠 \ 来分隔引号,这样您的命令就变成了

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

或者,将引号替换为 chr(34) 并将字符串附加到 &