Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: How can I cut a String based on a Value?

Tags:

string

c#

I have this string:

value1*value2*value3*value4

How would cut the String in multiple Strings?

string1 = value1;
string2 = value2;
etc...

My way (and probably not a very good way): I take an array with all the indexes of the "*" character and after that, I call the subString method to get what I need.

like image 277
cc. Avatar asked Jan 29 '26 16:01

cc.


2 Answers

string valueString = "value1*value2*value3*value4";
var strings = valueString.Split('*');
string string1 = strings[0];
string string2 = strings[1];
...

More info here.

like image 165
Gerrie Schenck Avatar answered Jan 31 '26 05:01

Gerrie Schenck


Try this

string string1 = "value1*value2*value3*value4";
var myStrings = string1.Split('*');
like image 35
Øyvind Bråthen Avatar answered Jan 31 '26 05:01

Øyvind Bråthen