Chr*_*ris 8 c# vb.net string split
我正在尝试将此代码从C#转换为VB.NET
string[] lines = theText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的,问题是它是在消息框中打印整个文本框内容,而不是每行.
Dim Excluded() As String
Dim arg() As String = {"\r\n", "\n"}
Excluded = txtExclude.Text.Split(arg, StringSplitOptions.None)
For i As Integer = 0 To Excluded.GetUpperBound(0)
MessageBox.Show("'" & Excluded(i) & "'")
Next
Run Code Online (Sandbox Code Playgroud)
你不能使用反斜杠(\)来转义VB中的字符.使用ControlChars课程:
Dim arg() As String = { ControlChars.CrLf, ControlChars.Lf }
Run Code Online (Sandbox Code Playgroud)
就字符串文字而言,转义序列在VB .Net中并不存在.
您可以使用2个特殊常量:
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
Run Code Online (Sandbox Code Playgroud)
应该做的伎俩(虽然未经测试).