Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert CString to integer

0 views
Skip to first unread message

AGF-Assubel User Information

unread,
Jan 29, 1998, 3:00:00 AM1/29/98
to

I'm searching simply for a method of conversion of a Cstring to integer :
Exemple:
CString str( "Minutes : 02");
int MyInt;
...
...
// I would like to have an integer named MyInt that have 2 as value.

Thank you very much for help.

email: robert....@agf.be

Bob


Katy Mulvey

unread,
Jan 29, 1998, 3:00:00 AM1/29/98
to

In <01bd2cc5$39f3cb60$570114ac@PC_Wrmndl.internal.agf.be>,
<robert....@agf.be> wrote:
>I'm searching simply for a method of conversion of a Cstring to integer :

I use the C-library function atoi to do this, e.g.

CString str("42");
int MyInt = atoi(str);

If you have a string that contains non-numerics, try

CString test("Zaphod Beeblebrox said 'Don't panic!' 42 times.");
int count = atoi(test.Mid(test.FindOneOf("0123456789")));

The argument to atoi in this case ends up as "42 times.", and
atoi ignores the trailing characters that aren't digits.

Katy

Thomas Blenkers

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to AGF-Assubel User Information

I can't believe it...

... but sometimes it's me asking the easiest questions as well!

MyInt = atoi(str.Mid(str.FindOneOf( "0123456789." )));

Thomas


>
> I'm searching simply for a method of conversion of a Cstring to
> integer :

0 new messages