Find an unknown string between two known characters

时间:2015-05-24 21:53:13

标签: c# unity3d

I need to be able to extract the three strings separated by a dashes "-" from an input string. For example:

Mystring="54-0-9";

the values separated by "-" are with unknown length because they should be an input for the user.

The user should enter each value in a textField than my code concatenate the 3 values and put it as shown . Later i want to get the three values separated again each one in a new text field. How can i do that in c# !?

2 个答案:

答案 0 :(得分:2)

Using string split.

// Select on "-".
string[] split = _string.Split(new Char[] { '-' });

split[0], split[1], split[2] will have the values you want.

答案 1 :(得分:2)

Mystring="54-0-9";
Mystring.Split('-');

this will give you a array of 3 now.