Possible Duplicate:
Is there an equivalent to 'sscanf()' in .NET?
sscanf in C is a nice way to read well formatted input from a string.
How to achieve this C#.
For example,
int a,b; char *str= "10 12"; sscanf(str,"%d %d",&a,&b);
The above code will assign 10 to a and 12 to b.
How to achieve the same using C#?
There is no direct equivalent in C#. Given the same task in C#, you could do it something like this:
string str = "10 12"; var parts = str.Split(' '); int a = Convert.ToInt32(parts[0]); int b = Convert.ToInt32(parts[1]);
Depending on how well-formed you can assume the input to be, you might want to add some error checks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With