Re: sscanf in c#




"AMP" <ampeloso@xxxxxxxxx> wrote in message
news:1158593340.752398.293970@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Hello,
| Anybody know if anything exists like sscanf in c.
| I found a few things OL but most were pretty old. Maybe something has
| come along since 2004?
| Thanks
| Mike
|

Ignore my previous post.
Using Parse and TryParse methods you can achieve the same (and more) results
as sscanf in C.
Consider following sample....

static void Main()
{
string tokenString = "12 25 56 4";
string [] split = tokenString.Split(new Char [] {' '});
int Int32Val;
char charVal;
float floatVal;
bool result = Int32.TryParse(split[0], NumberStyles.Integer, null, out
Int32Val);
if(result)
Console.WriteLine(Int32Val);
result = Char.TryParse(split[1][0].ToString(), out charVal);
if(result)
Console.WriteLine(charVal);
result = Single.TryParse(split[2], NumberStyles.Float, null, out
floatVal);
if(result)
Console.WriteLine("{0:f}", floatVal);
}


This should output:

12
2
56,00

Willy.




.



Relevant Pages

  • Re: sscanf in c#
    ... |> | Anybody know if anything exists like sscanf in c. ... |> Using Parse and TryParse methods you can achieve the same ... I prefer using TryParse over RegEx, just a matter of taste, and quite ... The closest he can get is by using Regex...sure, you can parse it yourself ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: sscanf in c#
    ... |> | Anybody know if anything exists like sscanf in c. ... |> Using Parse and TryParse methods you can achieve the same ... | HTH, ... I prefer using TryParse over RegEx, just a matter of taste, and quite faster ...
    (microsoft.public.dotnet.languages.csharp)