VB.NET 换行拆分(C# 转换)
我正在尝试将此代码从 C# 转换为 VB.NET
string[] lines = theText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
这是我所拥有的,问题是它打印消息框中的整个文本框内容,而不是每一行。
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
I'm trying to convert this code from C# to 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不能使用反斜杠 (
\
) 来转义 VB 中的字符。使用ControlChars
类:You can't use backslash (
\
) to escape characters in VB. Use theControlChars
class:就字符串文字而言,转义序列实际上并不存在于 VB .Net 中。
您可以使用 2 个特殊常量来代替:
vbCrLf
vbLf
应该可以解决问题(尽管未经测试)。
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
Should do the trick (untested though).
来自 在线转换器:
您的 C# 代码:
string[ ]lines = theText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
转换为 VB.NET:
From an online converter:
Your c# code:
string[] lines = theText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
Converted to VB.NET: