I have a specification where the user needs to type in a string of pair of co-ordinates like:
{{2,3}, {9,0}}
these are the co-ordinates of a line on a 2-D axis.
I want to parse this user-input string during runtime dynamically in C# and enter these co-ordinates in a 2-D array. I know we can do hard-coded:
int[,] CoOrdinates = {{2,3}, {9,0}};
but I do not know how to get the user to type in a string and get the co-ordinates from the string to store in the array dynamically.
I’m using Console.Readline(); to get the user to input the co-ordinates.
Please help, thanks!
I would use a regular expression (
Regexclass in C#) to parse out the bits of the string you want, and thenInt32.TryParse()to convert the string to a number. This is a good resource for constructing regular expressions, and this is my preferred regex tester. Good luck.