-2

I need to slip a string in c#. The string looks like this:

string b = "aaaaa-bbbbb-ccccc_ddddd_eeeee";

I want to cut the string in 4 and save the aaaaa in one new string, the bbbbb in another new string, and so on till i have the aaaaa,bbbbb,ccccc,ddddd,eeeee in new string, all separated. Example of wat i want in the end:

string a = "aaaaaaa";
string b = "bbbbbbb";
string a = "ccccccc";
string c = "ddddddd";
string e = "eeeeeee";

ps: i DONT want to store the strings in a array after they are split. I want to store them in NEW string variables.

elmnt57
  • 19
  • 1
  • 1
  • 6

1 Answers1

4

Use String.Split:

var items = b.Split(new char[] { '-', '_'} );

or Simply:

var items = b.Split( '-', '_' );

Here is full code:

string bb = "aaaaa-bbbbb-ccccc_ddddd_eeeee";
var items = bb.Split('-', '_');
string a = items[0];
string b = items[1];
string c = items[2];
string d = items[3];
string e = items[4];
Sadique
  • 22,572
  • 7
  • 65
  • 91