Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > atof, strtod on NSMutableString (or NSString)

atof, strtod on NSMutableString (or NSString)
Thread Tools
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 24, 2001, 10:54 AM
 
How do I invoke a command similar to "(float)atof(char *str)" or "scanf()"on an NSString or NSMutableString?

I need to extract a float value from a string, so something like:

@"123.23445" should become a float with that value (123.23445).

Thanks.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 24, 2001, 11:43 AM
 
In NSString, use - (double)doubleValue

and what do you mean similar to scanf()? scanf() is used to get input from the command line. Sure you could take a character array from scanf or NSString and convert it to a number, but there's no point in wasting time coding that if you can just use a method in NSString.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 24, 2001, 02:50 PM
 
Ah. I'll try that.

What I mean by scanf is like extracting a few doubles from a string, or a double, then a character, like "%d %c %d %c" or something like that.

Thanks!
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
ali
Forum Regular
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jan 24, 2001, 05:36 PM
 
Check out the NSScanner class.

It allows you to extract doubles, ints, strings, characters (from a given set) from a string. Basically similar to scanf() but less error prone. 8-)

Ali
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2