 |
 |
atof, strtod on NSMutableString (or NSString)
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
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
|
|
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
|
|
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)
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
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
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|