Concurrentdictionary Getoradd Async

Looking for C# equivalent of scanf

If regular expressions aren't working for you, I've just posted a sscanf() replacement for .NET. The code can be viewed and downloaded at http://www.blackbeltcoder.com/Articles/strings/a-sscanf-replacement-for-net.

C# equivalent of C sscanf

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.

c# equivalent of fscanf()

var parts = streamReader.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
int x = Int32.Parse(parts[0]);
int y = Int32.Parse(parts[1]);

how do I do sscanf in c#

If like scannf you are willing to assume that users will give completely correct data then you can do the following.

string astring = ...;
string[] values = astring.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
int a = Int32.Parse(values[0]);
int b = Int32.Parse(values[1]);
int c = Int32.Parse(values[2]);

Regular expressions would work for this scenario but they are a bit overkill. The string can easily be tokenized with the aforementioned Split method.

c# equivalent of fscanf()

var parts = streamReader.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
int x = Int32.Parse(parts[0]);
int y = Int32.Parse(parts[1]);


Related Topics



Leave a reply



Submit