Search code examples
c#regexvb.netstringwords

C# How to get Words From String


Hi guys i was trying a lot to retrieve some other strings from one main string.

string src = "A~B~C~D";

How can i retrieve separately the letters? Like:

string a = "A";
string b = "B";
string c = "C";
string d = "D";

Solution

  • Try this one. It will split your string with all non-alphanumeric characters.

    string s = "A~B~C~D";
    string[] strings = Regex.Split(s, @"\W|_");