regex - How would I split TO extract spaces in C# -


split or regex.split used extract word in sentence(s) , store them in array. instead extract spaces in sentence(s) , store them in array (it possible sentence contains multiple spaces). there easy way of doing it? first tried split normally, , use string.split(thesplittedstrings, stringsplitoptions.removeemptyentries) however, did not preserve amount of spaces exists.

---------- edit -------------

for example. if there sentence "this test". make array of string { " ", " ", " "}.

---------- edit end ---------

any helps appreciated.

thank you.

this code matches spaces in input string , outputs indexes:

const string sentence = "this  test   sentence."; matchcollection matches = regex.matches(sentence, @"\s");  foreach (match match in matches) {     console.writeline("space @ character {0}", match.index); } 

this code retrieves space groups array:

const string sentence = "this  test   sentence."; string[] spacegroups = regex.matches(sentence, @"\s+").cast<match>().select(arg => arg.value).toarray(); 

in either case, can @ match instances' index property values location of space/space group in string.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -