Re: sscanf in c#



Also, theres this qualifier (3), which is the max number to read, in
the following that I would have to deal with.
sscanf(strdata[linepos], "%3x", blkout[dataframelen]);

I appreciate EVERONES help with this.


AMP wrote:
Hello,
I am the OP.
I am beginning to understand but I have the following:
sscanf(strdata[1], "%lx\n", currentAddr);

currentAddr is an unsigned long in c(which is a uint in c#) 4 bytes,
correct?

I am trying to get the hang of this, but I could use an example with
something I'm using.
I have to convert about 8 of these to dfferent formats, so its
important I can understand what I;m doing.

Thanks
Mike

Mythran wrote:
"Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
news:ewAm8nA3GHA.4484@xxxxxxxxxxxxxxxxxxxxxxx

"Mythran" <kip_potter@xxxxxxxxxxx> wrote in message
news:%23Q6bbEA3GHA.1548@xxxxxxxxxxxxxxxxxxxxxxx
|
| "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
| news:Owmw%23s32GHA.4932@xxxxxxxxxxxxxxxxxxxxxxx
| >
| > "Mythran" <kip_potter@xxxxxxxxxxx> wrote in message
| > news:uSleo322GHA.1040@xxxxxxxxxxxxxxxxxxxxxxx
| > |
| > | "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in
message
| > | news:eQCLID22GHA.1068@xxxxxxxxxxxxxxxxxxxxxxx
| > | >
| > | > "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.
| > | >
| > | >
| > | >
| > | >
| > |
| > | Well, suppose you have the following string:
| > |
| > | "Item #1: $32.53 Item #2: $32.54 Sub-Total: $65.07"
| > |
| > | With sscanf, I believe you can do something like:
| > |
| > |
| > | sscanf(buff, "Item #1: $%d Item #2: $%d Sub-Total: $%d", value1,
value2,
| > | value3);
| > | printf("Sub-Total: %d", value3);
| > |
| > |
| > | Using regex, you can do something similar...and parsing out yourself
| > would
| > | be more trickier...
| > |
| > | HTH,
| > | Mythran
| > |
| >
| > I prefer using TryParse over RegEx, just a matter of taste, and quite
| > faster
| > ;-)
| >
| > // suppose the current culture is en-US...
| > Decimal decVal;
| > string tokenString = "Item #1: $32.53 Item #2: $32.54 Sub-Total:
| > $65.07";
| > string [] split = tokenString.Split(new Char [] {' '});
| > bool result = Decimal.TryParse(split[7], NumberStyles.Currency,
null,
| > out decVal);
| > if(result)
| > Console.WriteLine("Sub-total: {0:c}", decVal);
| >
| > Not really tricky IMO.
| >
| > Willy.
| >
| >
|
| grr, that's not my point. The OP requested similar functionality to
sscanf.
| The closest he can get is by using Regex...sure, you can parse it
yourself
| into an array and access the individual elements, but that's not what
the
OP
| was originally asking AFAIK (even though, it should work for the OP).
| Anywho :)
|
| Mythran
|

Sorry, but I'm affraid we'll have to agree to disagree. I don't see how a
simple C library 'function' like sscanf compares to Regex, a 'library' and
a
complex engine on it's own, it's too heavy weight compared to sscanf.

I know you can achieve the same using RegEx, but I can do exactly that
using
some minimal code arround the individual type's Parse and TryParse
methods.
Notice, that the OP asks about sscanf, this means he has a C background,
chances are that he know little/nothing about RegEx, maybe he will prefer
to
use Parse and TryParse, the choice will be on him.


Willy.

|



I do see where you are coming from. And yes, I will continue to disagree as
we have previously agreed to allow :) On second thought, maybe I will agree
with you about parsing out manually depending on the amount of data the OP
needs to parse. If it is a larger amount of data, and performance isn't an
issue, then I would then go with Regex for this.

:)

Mythran

.



Relevant Pages

  • Re: sscanf in c#
    ... formatting it and storing it in blkout. ... |> | With sscanf, I believe you can do something like: ... |> I prefer using TryParse over RegEx, just a matter of taste, and quite ... some minimal code arround the individual type's Parse and TryParse ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: sscanf in c#
    ... |> | With sscanf, I believe you can do something like: ... |> I prefer using TryParse over RegEx, just a matter of taste, and quite ... some minimal code arround the individual type's Parse and TryParse ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: sscanf in c#
    ... |> | With sscanf, I believe you can do something like: ... |> I prefer using TryParse over RegEx, just a matter of taste, and quite ... some minimal code arround the individual type's Parse and TryParse ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: sscanf in c#
    ... |> | With sscanf, I believe you can do something like: ... |> I prefer using TryParse over RegEx, just a matter of taste, and quite ... some minimal code arround the individual type's Parse and TryParse methods. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: sscanf in c#
    ... | needs to parse. ... This illustrates the equivalence of sscanf and Parse (or preferably: ... I would never use RegEx for this. ...
    (microsoft.public.dotnet.languages.csharp)