I have the following code
string tString;
int flNum;
string flLeg;
tString = "25664-A";
I need to get tString into two variables, flNum and flLeg.
My desired results are- flNum = 25664 flLeg = A
My attempt was –
flNum = Convert.ToInt32(tString.Substring(tString.IndexOf("-") - 1));
flLeg = tString.Substring(tString.IndexOf("-") + 1, 1);
But it errors out on me. Any suggestions on how to change this code in order to get my desired results?
Thanks for you assistance.
You could simply use the string.Split() method.
In your code, you get an error because, for the first substring, you need to pass a starting point and a length
You find correctly the position of the dash, but this position is passed as the starting point to substring but there is no number starting from the pos passed, so the conversion fails.
(And remove the – 1 for the length because this is…. well a length not a position)