I am currently working on a programming language, and my friend asked me to convert it to a console application and, so far it hasn't been going well
if (input.Contains(""))
{
string name = input.Substring(0, 3);
string value = input.Substring(4);
Console.WriteLine("Name:" + name + " " + "Value:" + value);
vars[Convert.ToInt32(name)] = value;
}
The line that says vars[Convert.ToInt32(name)] = value; has been giving me errors
when I run it the first 3 lines above it work this is an example of what I would type in the console str Hello and it would print Name:str Value:Hello but then it stops the program and shows me this error
Input string was not in a correct format.
I'm not to familiar with this error but if you have ever programmed in Lua this is what im trying to accomplish
elseif line:match("^int") then
local n, v = line:match("^int (.+) = (%d+)")
vars[n] = v
I always had a problem with arrays in C#, so if you could please tell me whats wrong it would help me a lot, Thanks in advance.
Convert.ToInt32(name)if name is not numeric (which most likely it isn't, given the variable namename) within the range ofintthen the format is incorrect.Convert.ToInt32(name)?input.Contains("")will always returntrue(or throw an exception ifinputisnull).Regexclass