Alan Alan - 3 months ago 9
C# Question

How can I split a string like "12-15" into two numbers?

My front-end application sends strings that look like this:


to a back-end C# application.

Can someone give me some pointers as to how I could extract the two numbers into two variables. Note the format is always the same with two numbers and a hyphen between them.


Split the string into parts:

string s = "12-15";
string[] num = s.Split('-');
int part1 = Convert.ToInt32(num[0]);
int part2 = Convert.ToInt32(num[1]);