Monday, April 29, 2013

C#: Split String Using a Variable Length Delimiter,Splitting Strings


Splitting Strings Using char[]


string words = "This is a list of words, with: a bit of punctuation.";string [] split = words.Split(new Char [] {' ', ',', '.', ':'});


This would produce the string array:
{ "This", "is", "a", "list", "of", "words", "with", "a", "bit", "of", "punctuation" }

Splitting Strings Using string[]

string words = "This is a list of words: aesthetics, praefect"; string[] separators = {", ", "ae"};
string[] split = words.Split(separators, StringSplitOptions.None);
This would produce the string array:
{ "This is a list of words: ", "sthetics", "pr", "fect" }

No comments:

Post a Comment