我有一个待办事项:
AccountList.Split(vbCrLf)
在C#中,AccountList是一个字符串变量。 我该如何处理它?
谢谢
我有一个待办事项:
AccountList.Split(vbCrLf)
在C#中,AccountList是一个字符串变量。 我该如何处理它?
谢谢
我通常会缩写以便在我的代码中多次使用。在代码的顶部附近,可以这样做:
string nl = System.Environment.NewLine;
当我构建字符串时,我可以仅使用"nl"而不是完整的限定词。
AccountList.Split("\r\n");
在您的项目中添加对Microsoft.VisualBasic的引用。
然后插入using语句。
using Microsoft.VisualBasic;
使用预定义的常量 vbCrLf:
private const string myString = "abc" + Constants.vbCrLf;
vbCrLf
的。没有必要使用ControlChars类。但结果是相同的。 - huhavbCrLf
常量在C#中没有等价物。C#的System.Environment.NewLine
是Visual Basic中vbNewLine
的等价物,它不是vbCrLf
的等价物,因为System.Environment.NewLine
的值取决于C#应用程序运行的操作系统(vbNewLine
同理) - 可以参考msdn链接。
在C#中,您可以使用"\r\n"
代替vbCrLf
,正如其中一个评论所提到的那样。
尝试这个:
AccountList.Split(new String[]{"\r\n"},System.StringSplitOptions.None);
或者
AccountList.Split(new String[]{"\r\n"},System.StringSplitOptions.RemoveEmptyEntries);
public string VB2 = System.Environment.NewLine + System.Environment.NewLine;
public string VBCrLf = System.Environment.NewLine;
MessageBox.Show("Error: " + VB2 + E.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation );
"FirstLine" + "<br/>" "SecondLine"
string[] strOptions = txtOptions.Text.Split(System.Environment.NewLine.ToCharArray());
如果在每个选项后按回车键有四个选项,它返回7个实例而不是4个。 - Si8