使用string.split时如何正确地转义双引号

时间:2015-11-05 12:27:26

标签: vb.net string

Dim mystring as string = " myintref="567" Mynewref="345" "

我想在每个单引号上拆分mystring,以便最终得到;

myintref= 567

Mynewref= 345

无论

Dim splitstring as string() = mystring.Split(""")

 Dim splitstring as string() = mystring.Split(New Char {"""c})

似乎有效。有什么建议? (vs2015,vb.net v14)

2 个答案:

答案 0 :(得分:3)

要在VB中转义双引号,只需使用两个连续的双引号字符。所以你可以这样做:

width: 100%;
position: absolute;
top: calc(50% - 10px);
left: 50%;
height: calc(100%);
-webkit-transform: translateY(-50%) translateX(-50%);

这导致将字符串拆分为双引号字符:

Debugging screen shot

答案 1 :(得分:0)

在分割该字符串后,您期待2个或4个元素吗?

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim strLine As String = " myintref=" & """" & "567" & """" & " Mynewref=" & """" & "345" & """" & " "
    Debug.WriteLine("Original: " & strLine)
    Dim strAry As String() = strLine.Split({""""c})
    For i As Int32 = 0 To strAry.Length - 1
        Debug.WriteLine(strAry(i))
    Next
End Sub

给我这个输出:

Original:  myintref="567" Mynewref="345" 
 myintref=
567
 Mynewref=
345