[英]VB.NET split on new lines (C# conversion)
I'm trying to convert this code from C# to VB.NET 我正在尝试将此代码从C#转换为VB.NET
string[] lines = theText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
Here's what I have, the problem is it is printing the whole of the text box contents in the messagebox, instead of each line. 这就是我所拥有的,问题是它是在消息框中打印整个文本框内容,而不是每行。
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
You can't use backslash ( \\
) to escape characters in VB. 您不能使用反斜杠( \\
)来转义VB中的字符。 Use the ControlChars
class: 使用ControlChars
类:
Dim arg() As String = { ControlChars.CrLf, ControlChars.Lf }
Escape sequences don't really exist in VB .Net as far as string literals are concerned. 就字符串文字而言,转义序列在VB .Net中并不存在。
There are 2 special constants which you can use instead: 您可以使用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
Should do the trick (untested though). 应该做的伎俩(虽然未经测试)。
From an online converter : 来自在线转换器 :
Your c# code: 你的c#代码:
string[] lines = theText.Split(new string[] { "\\r\\n", "\\n" }, StringSplitOptions.None);
Converted to VB.NET: 转换为VB.NET:
Dim lines As String() = theText.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.