I'm working on to read a textfile which contains this line of string. And to fetch its value to my integer variables.. I want to try to avoid using Class or Arrays.
string cont = "[]val1:1val2:0val3:1";
int split = cont.IndexOf("val3:");
int val3 = Int32.Parse(cont.Substring(split + 5)); // this line successfully convert string to int
cont.Remove(split);
Console.WriteLine("Value3: " + val3 + " Content: " + cont);
split = cont.IndexOf("val2:");
int val2 = Int32.Parse(cont.Substring(split + 5)); // LINE 21
cont.Remove(split);
Console.WriteLine("Value2: " + val2 + " Content: " + cont);
split = cont.IndexOf("val1:");
int SilverCoins = Int32.Parse(cont.Substring(split + 5));
cont.Remove(split);
Console.WriteLine("Value1: " + val1 + " Content: " + cont);
When I run this code, I get an Unhandled Exception which states Input string was not in a correct format, at System.Int32.Parse(String s), line 21
. :(
So, my desired output should be
Value3: 1 Content: []val1:1val2:0
Value2: 0 Content: []val1:1
Value1: 1 Content: []