Re: sscanf in c#
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Mon, 18 Sep 2006 22:26:51 +0200
"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.
.
- Follow-Ups:
- Re: sscanf in c#
- From: Mythran
- Re: sscanf in c#
- References:
- sscanf in c#
- From: AMP
- sscanf in c#
- Prev by Date: c# drag and drop
- Next by Date: Re: Drop down a combobox programatically ?
- Previous by thread: Re: sscanf in c#
- Next by thread: Re: sscanf in c#
- Index(es):
Relevant Pages
|