cocoa - Efficient conversion of int to string -
i've seen several questions/answers here suggest best way string representation of integer in objective-c use [nsstring stringwithformat:@"%d", x]
. i'm afraid c/c++ programmer in me having hard time believing want bring formatting code play such simple task. is, assume stringwithformat
needs parse through format string looking different type specifiers, field widths, , options possibly use, has able interpret variable length list of parameters , use format specifier coerce x
appropriate type, go through lengthy process of conversion, accounting signed/unsigned values , negation along way.
needless in c/c++ use itoa(x)
1 thing , extremely efficiently.
i'm not interested in arguing relative merits of 1 language on another, rather asking question: incredibly powerful [nsstring stringwithformat:@"%d", x]
really efficient way very, simple task in objective-c? seems i'm cracking peanut sledge hammer.
you use itoa()
followed of +[nsstring stringwithutf8string:]
-[nsstring initwithbytes:length:encoding:
or +[nsstring stringwithcstring:encoding:]
if makes feel better, wouldn't worry unless you're sure performance problem.
Comments
Post a Comment