可能重复:
在 VB 字符串中转义双引号
我在下面用字符串值分配变量,我想用引号打印这些变量,尽管我不确定如何完成这个。到目前为止,一切都打印得很好,除了没有引号。我所拥有的如下:
Dim tU As String = "Print_Me"
Dim tU2 As String = ""
Dim str1 As Integer = 1
Dim str2 As String = tU
Dim str3 As Single = 3.5
Dim str4 As String = tU2
Dim fw As New System.IO.StreamWriter("testfile.txt")
fw.WriteLine(str1 & "," & str2 & "," & str3 & "," & str4 & "," & 0)
fw.Close()
fw.Dispose()
'prints>>>1,Print_Me,3.5,,0<<<
'I like to print>>>1,"Print_Me",3.5,"",0<<<
编辑
Dim tU As String = "Print_Me"
Dim tU2 As String = ""
Dim str1 As Integer = 1
Dim str2 As String = tU
Dim str3 As Single = 3.5
Dim str4 As String = tU2
Dim str5 As Integer = 0
Using fw As New System.IO.StreamWriter("testfile.txt")
fw.WriteLine(String.Format("""{0}"",""{1}"",""{2}"",""{3}"",""0""", str1, str2, str3, str4, str5))
End Using
''Currently prints>>> "1","Print_Me","3.5","","0"
''I would like to print>>> 1,"Print_Me",3.5,"",0
我通过 str5 间接填充 str1,但我不想打印所有带有引号的项目,那么我该如何调整解决方案来实现这一点?