c# - Splitting strings in a "Google" style way -
i trying create function split string search terms. using code work fine:
string teststring = "this test"; string[] terms; terms = teststring.split(" ");
this split string 4 strings: "this", "is", "a", "test". want words enclosed in quotes treated 1 word:
string teststring = "this \"test will\" fail"; string[] terms; terms = teststring.split(" ");
this split string 4 strings, again: "this", "\"test", "will\"", "fail"
what want split last string 3 strings: "this", "test will", "fail"
anyone have idea on how this?
try using regex:
var teststring = "this \"test will\" fail"; var termsmatches = regex.matches(teststring, "(\\w+)|\"([\\w ]+[^ ])\"");
Comments
Post a Comment