VB.NET split on new lines (C# conversion)

前端 未结 3 1062
别跟我提以往
别跟我提以往 2021-01-05 02:30

I\'m trying to convert this code from C# to VB.NET

string[] lines = theText.Split(new string[] { \"\\r\\n\", \"\\n\" }, StringSplitOptions.None);
         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 03:16

    Escape sequences don't really exist in VB .Net as far as string literals are concerned.

    There are 2 special constants which you can use instead:

    vbCrLf
    vbLf

    Dim Excluded() As String
    
    Dim arg() As String = {vbCrLf, vbLf}
    
    Excluded = txtExclude.Text.Split(arg, StringSplitOptions.None)
    
    For i As Integer = 0 To Excluded.GetUpperBound(0)
        MessageBox.Show("'" & Excluded(i) & "'")
    Next
    

    Should do the trick (untested though).

提交回复
热议问题