Split a string that has white spaces, unless they are enclosed within “quotes”?

后端 未结 7 718
无人共我
无人共我 2020-11-30 00:12

To make things simple:

string streamR = sr.ReadLine();  // sr.Readline results in:
                                 //                         one \"two two\         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 00:51

    string input = "one \"two two\" three \"four four\" five six";
    var parts = Regex.Matches(input, @"[\""].+?[\""]|[^ ]+")
                    .Cast()
                    .Select(m => m.Value)
                    .ToList();
    

提交回复
热议问题