私は最近、以前はそうしていた場所TextFieldParserを解析することを学びました。そして、新しく学んだ について質問があります。wordsstring.Splitclass
withを使用してこのようなメッセージを解析するstring.SplitとStringSplitOptions.RemoveEmptyEntries
string message = "create myclass \"56, 'for better or worse'\""; //have multiple spaces
string[] words = message.Split(new char[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);
次にwords、次のような 3 つの要素を含む whichを取得します。
[0] create
[1] myclass
[2] "56, 'for better or worse'"
しかし、私たちがそれを行うとTextFieldParser
string str = "create myclass \"56, 'for the better or worse'\"";
var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(new StringReader(str)); //treat string as I/O
parser.Delimiters = new string[] { " " };
parser.HasFieldsEnclosedInQuotes = true;
string[] words2 = parser.ReadFields();
次に、return遺言はwordsテキストのないもので構成されます
[0] create
[1]
[2]
[3]
[4] myclass
[5]
[6]
[7] "56, 'for better or worse'"
words結果の配列の空を削除する同等の方法はありstring.Split StringSplitOptions.RemoveEmptyEntriesますか?