常量以c#中的回车符(CR)拆分字符串

Our*_*nas 1 c# string tokenize

我试图将一个字符串拆分为两个数组.

第一个数组在字符串的开头有数据,由\t(tab)字符分割,其余部分在第一个换行符(\n)后面.

我试过这个,认为这就是我想要的:

string[] pqRecords = pqRequests.ToString().Split('\n');
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

internal static readonly string segment = Environment.NewLine + "\t";
string[] pqRecords = pqRequests.ToString().Split(segment);
Run Code Online (Sandbox Code Playgroud)

不幸的是,该Split方法只需要一个字符.

我知道我的pqRequests字符串变量中有vbcr,因为当我将鼠标悬停在它上面并看到文本可视化时,第一行有标签,其他一切都在它自己的行上.

这个数据取自txt文件,在文件中,当在Notepad ++中打开时,我可以看到这些CR字符.

c#中是否有替代常量我应该用于这些CR字符?

Jon*_*Jon 5

string.Split 很乐意接受多个分隔符.你只需要将它们作为数组传递:

internal static readonly string segment = Environment.NewLine + "\t";
string[] pqRecords = pqRequests.ToString().Split(segment.ToArray());
Run Code Online (Sandbox Code Playgroud)

当然,你可以(并且应该)更清楚地写出相同的内容

internal static readonly char[] separators = new[] { '\n', '\t' };
string[] pqRecords = pqRequests.ToString().Split(separators);
Run Code Online (Sandbox Code Playgroud)