Link to home
Start Free TrialLog in
Avatar of andyw27
andyw27

asked on

Splitting String into Int

Hi,

I have a simple string 35,1

Which is separated by a comma.

Taking this string I need to output two int’s

X = 35
Y = 1

Is this possible please?
ASKER CERTIFIED SOLUTION
Avatar of regmigrant
regmigrant
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi.. this is your solution
string str = "35,1";

string [ ] str1 = str.split(",");
int n1 = convert.toInt(str1[0].toString());
int n2 = convert.toInt(str1[1].toString());

try this I hope it's working...
You can also use one-liners:

string v = "35,1";
int x = Convert.ToInt32(v.Split(',')[0]);
int y = Convert.ToInt32(v.Split(',')[1]);

/gustav