473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

sscanf

Does anyone know a equivalent to sscanf from c++.

I would appreciate a good answer to this one, since currently I have had to
write a library of regular expressions to recognise integers, floats etc..
and I dont want to use exceptions or anything else that is slow or
impractical.

Much thanks.

Evan
Nov 16 '05 #1
3 3990
Evan Mathias wrote:
Does anyone know a equivalent to sscanf from c++.

I would appreciate a good answer to this one, since currently I have
had to write a library of regular expressions to recognise integers,
floats etc.. and I dont want to use exceptions or anything else that
is slow or impractical.


Well I was going to suggest the regex classes, but then I read you
didn't want to use anything slow and impractical ;-)

So assuming you don't want to use the regex classes I think that what
you want is a combination of the split method of the string and then
the appropriate convert routine. i.e

/*untested, as it was written in the news reader*/

string[] theValues = buffer.Split(**yourDelims**);

double theDoubleValue = Convert.ToDouble(theValues[0]);
int32 theIntValue = Convert.ToInt32(theValues[1]);

etc, etc

Obviously you would have the appropriate error checking and handling.

Cheers Tim.

Nov 16 '05 #2
Thanks Tim

I have found the regex class fast, my real issue was the amount of code
required to build a library and it was not really appropriate for the same
things sscanf was used to do. My options were to implement regex, use split
or bring across scannf from c++. Split seemed to be really quite slow, since
I would normally use something like

If (Sscanf(str, "%i, %f FACTOR 4s %f), a, b, c, d) == 4) {}

Hence using split and convert would generate many exceptions, and thus have
a massive performance hit. I assume there must be an option in managed code.
"Tim Jarvis" <Ti*******@newsgroup.nospam> wrote in message
news:Od**************@TK2MSFTNGP09.phx.gbl...
Evan Mathias wrote:
Does anyone know a equivalent to sscanf from c++.

I would appreciate a good answer to this one, since currently I have
had to write a library of regular expressions to recognise integers,
floats etc.. and I dont want to use exceptions or anything else that
is slow or impractical.


Well I was going to suggest the regex classes, but then I read you
didn't want to use anything slow and impractical ;-)

So assuming you don't want to use the regex classes I think that what
you want is a combination of the split method of the string and then
the appropriate convert routine. i.e

/*untested, as it was written in the news reader*/

string[] theValues = buffer.Split(**yourDelims**);

double theDoubleValue = Convert.ToDouble(theValues[0]);
int32 theIntValue = Convert.ToInt32(theValues[1]);

etc, etc

Obviously you would have the appropriate error checking and handling.

Cheers Tim.

Nov 16 '05 #3
Evan Mathias wrote:
thus have a massive performance hit. I assume there must be an option
in managed code.


I'm not sure there is a close equivalent, not that I know of anyway.

Cheers Tim
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Allan Bruce | last post by:
If I have sscanf("FL:%s:%d:%s\n", lGuid, &lID, lFileName); and the last string contains spaces, e.g. my complete string "FL:1234ABCD:3:FileName With Spaces.txt\n" does sscanf just make...
4
by: smshahriar | last post by:
Hi, I want to scan from the following string all the hex numbers and populate an array of integers: 0x27 0x00 0x30 0x00 0x33 0x00 0x36 0x00
10
by: baumann | last post by:
hi, 1) first test program code #include <stdio.h> int main(void) { char * file = "aaa 23 32 m 2.23 ammasd"; int i2,i3;
4
by: baumann | last post by:
hi all there has 2 program 1) the first test program code #include <stdio.h> int main(void) {
5
by: jchludzinski | last post by:
I'm using strtok() to parse thru a line and read different numbers: float value; char *token; token = strtok( line, " " ); .... sscanf( token, "%f", &value ); These results are less...
22
by: Superfox il Volpone | last post by:
Hello I have some problem with sscanf, I tryed this code but it doesn't works : char* stringa = "18/2005" char mese; char anno; int i_letture; i_letture = sscanf(stringa, "%2s/%4s",...
8
by: Artemio | last post by:
Dear folks, I need some help with using the sscanf() function. I need to parse a string which has several parameters given in a "A=... B=... C=..." way, and each has a different type (one is a...
20
by: AMP | last post by:
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
5
by: Alex Mathieu | last post by:
Hi, using sscanf, I'm trying to retrieve something, but nothing seems to work. Here's the pattern: SS%*sþ0þ%6s Heres the data: SS000000395000000000DC-þ0þ799829þ1174503725þ Actually, I...
7
by: gio | last post by:
suppose I have: .... char str1; char str2; int ret; fgets(str1, LEN, stdin); //str1 can contain just '\n' and '\0' ret=sscanf(str1, "%s", str2); ....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.