Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将长字符串转换为C中的列表_C#_String - Fatal编程技术网

C# 将长字符串转换为C中的列表

C# 将长字符串转换为C中的列表,c#,string,C#,String,字符串如下所示: "c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n" // replace \r\n to ; and split it... it will be your lines var lines = text.replace("\r\n", ";").Split(';'); // split every item of the line arrays by , and get an new array to each item L

字符串如下所示:

"c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
// replace \r\n to ; and split it... it will be your lines
var lines = text.replace("\r\n", ";").Split(';');

// split every item of the line arrays by , and get an new array to each item
List<string[]> arrays = lines.Select(x => x.Split(',')).ToList();
这条线路的工作原理是:

IEnumerable<string[]> lineFields = File.ReadAllLines(sFile).Select(line => line.Split(','));
List<string[]> lLines = lineFields.ToList();
但假设我不是从文件中读取,而是我前面描述的字符串

我提到的将performance转换为字符串[]列表的最快方法是什么

List<string[]> lLines = [ [c,c,c,c,c] , [c,c,c,c,c] , ... [c,c,c,c,c] ]
谢谢。

试试这个

string combindedString = string.Join( ",", myList );
试试这个

string combindedString = string.Join( ",", myList );
试试这个

string combindedString = string.Join( ",", myList );
试试这个

string combindedString = string.Join( ",", myList );

试着这样做:

"c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
// replace \r\n to ; and split it... it will be your lines
var lines = text.replace("\r\n", ";").Split(';');

// split every item of the line arrays by , and get an new array to each item
List<string[]> arrays = lines.Select(x => x.Split(',')).ToList();

试着这样做:

"c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
// replace \r\n to ; and split it... it will be your lines
var lines = text.replace("\r\n", ";").Split(';');

// split every item of the line arrays by , and get an new array to each item
List<string[]> arrays = lines.Select(x => x.Split(',')).ToList();

试着这样做:

"c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
// replace \r\n to ; and split it... it will be your lines
var lines = text.replace("\r\n", ";").Split(';');

// split every item of the line arrays by , and get an new array to each item
List<string[]> arrays = lines.Select(x => x.Split(',')).ToList();

试着这样做:

"c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
// replace \r\n to ; and split it... it will be your lines
var lines = text.replace("\r\n", ";").Split(';');

// split every item of the line arrays by , and get an new array to each item
List<string[]> arrays = lines.Select(x => x.Split(',')).ToList();

像这样的方法应该会奏效:

var list = "c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
    .Split('\n')
    .Select(s => s.Trim().Split(','));

像这样的方法应该会奏效:

var list = "c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
    .Split('\n')
    .Select(s => s.Trim().Split(','));

像这样的方法应该会奏效:

var list = "c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
    .Split('\n')
    .Select(s => s.Trim().Split(','));

像这样的方法应该会奏效:

var list = "c,c,c,c,c,c\r\nc,c,c,c,c,c\r\n.....c,c,c,c,c\r\n"
    .Split('\n')
    .Select(s => s.Trim().Split(','));


我认为OP想要创造List@Yanshof,谢尔盖是对的。我想创建列表我想OP想创建List@Yanshof,谢尔盖是对的。我想创建列表我想OP想创建List@Yanshof,谢尔盖是对的。我想创建列表我想OP想创建List@Yanshof,谢尔盖是对的。我想创建列表我想你已经准备好了使用拆分的fastet方法。要求使用最快的方法可能不会得到你期望的结果,因为性能将取决于字符串的长度以及其他因素。你准备好在你将得到的所有答案中对代码进行基准测试了吗?使用一些基准测试。使用System.Diagnostics.StopWatch进行测量。我认为您已经准备好使用快速分割法。要求以最快的方式进行测量可能不会得到您期望的结果,因为性能将取决于字符串的长度等。你准备好在你将得到的所有答案中对代码进行基准测试了吗?使用一些基准测试。使用System.Diagnostics.StopWatch进行测量。我认为您已经准备好使用快速分割法。要求以最快的方式进行测量可能不会得到您期望的结果,因为性能将取决于字符串的长度等。你准备好在你将得到的所有答案中对代码进行基准测试了吗?使用一些基准测试。使用System.Diagnostics.StopWatch进行测量。我认为您已经准备好使用快速分割法。要求以最快的方式进行测量可能不会得到您期望的结果,因为性能将取决于字符串的长度等。你准备好在你将得到的所有答案中对代码进行基准测试了吗?使用一些基准测试。使用System.Diagnostics.StopWatch进行测量。工作起来很有魅力!谢谢顺便说一句,是否有必要跳过替换行以提高性能?在大型数据集上执行这样的替换会慢得多-因为您必须在初始字符串的内存中创建并分配一个完整的字符串-尽管有替换的字符。所以-如果一个100毫克的初始字符串-这将需要至少200毫克的处理。工程像一个魅力!谢谢顺便说一句,是否有必要跳过替换行以提高性能?在大型数据集上执行这样的替换会慢得多-因为您必须在初始字符串的内存中创建并分配一个完整的字符串-尽管有替换的字符。所以-如果一个100毫克的初始字符串-这将需要至少200毫克的处理。工程像一个魅力!谢谢顺便说一句,是否有必要跳过替换行以提高性能?在大型数据集上执行这样的替换会慢得多-因为您必须在初始字符串的内存中创建并分配一个完整的字符串-尽管有替换的字符。所以-如果一个100毫克的初始字符串-这将需要至少200毫克的处理。工程像一个魅力!谢谢顺便说一句,是否有必要跳过替换行以提高性能?在大型数据集上执行这样的替换会慢得多-因为您必须在初始字符串的内存中创建并分配一个完整的字符串-尽管有替换的字符。所以-如果一个100毫克的初始字符串-这将需要至少200毫克的处理。这也很好。如果我们对表演感兴趣,你们有什么建议?我的数据集太小,无法与Felipe的答案或这一个进行比较?谢谢。@Mockingbird-见上面的评论这也很有效。如果我们对表演感兴趣,你们有什么建议?我的数据集太小,无法与Felipe的答案或这一个进行比较?谢谢。@Mockingbird-见上面的评论这也很有效。如果我们对表演感兴趣,你们有什么建议?我的数据集太小,无法与Felipe的答案或这一个进行比较?谢谢。@Mockingbird-见上面的评论这也很有效。如果我们对表演感兴趣,你们有什么建议?我的数据集太小,无法与Felipe的答案或这一个进行比较?谢谢。@Mockingbird-见上面的评论