私は最近、以前はそうしていた場所TextFieldParser
を解析することを学びました。そして、新しく学んだ について質問があります。words
string.Split
class
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
ますか?