VB.NET在新行中拆分(C#转换) [英] VB.NET split on new lines (C# conversion)
本文介绍了VB.NET在新行中拆分(C#转换)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将此代码从C#转换为VB.NET
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
推荐答案
就字符串文字而言,VB .Net中实际上并不存在转义序列.
Escape sequences don't really exist in VB .Net as far as string literals are concerned.
您可以使用2个特殊常量代替:
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).
这篇关于VB.NET在新行中拆分(C#转换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文