Csharp/C#教程:VB.NET拆分新行(C#转换)分享


VB.NET拆分新行(C#转换)

我正在尝试将此代码从C#转换为VB.NET

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

这就是我所拥有的,问题是它是在消息框中打印整个文本框内容,而不是每行。

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

就字符串文字而言,转义序列在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 

应该做的伎俩(虽然未经测试)。

您不能使用反斜杠( )来转义VB中的字符。 使用ControlChars类:

 Dim arg() As String = { ControlChars.CrLf, ControlChars.Lf } 

从在线转换器 :

你的c#代码:

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

转换为VB.NET:

上述就是C#学习教程:VB.NET拆分新行(C#转换)分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 Dim lines As String() = theText.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None) 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1029153.html

(0)
上一篇 2022年1月12日
下一篇 2022年1月12日

精彩推荐