开发者

how to convert NSinteger to String [duplicate]

开发者 https://www.devze.com 2023-01-18 05:38 出处:网络
This question already has answers here: How to convert int to NSString? (4 answers) Closed 8 years ago. I want to convet int to string in objective c how to do that.
This question already has answers here: How to convert int to NSString? (4 answers) Closed 8 years ago.

I want to convet int to string in objective c how to do that.

my code.

for (i=0; i<=200; i=i开发者_如何学Go+10) {
    // here i want to convet the value of i into string how to do this 

}   

Thanks in Advance.


Try this:

NSMutableString *myWord = [[NSMutableString alloc] init];
for (int i=0; i<=200; i=i+10) {
    [myWord appendString:[NSString stringWithFormat:@"%d", i]];
    //...
}
//do something with myWord...
[myWord release];

NSInteger is simply a typedef to the int or long data types on 32/64-bit systems.


NSInteger n = 13;
NSString string = @(n).stringValue;

Reference see Objective-C literals - literals remove lots of ugly boilerplate code cluttering up your codebase: http://clang.llvm.org/docs/ObjectiveCLiterals.html


You may want to declare myWord out of the loop as NSMutableString.

0

精彩评论

暂无评论...
验证码 换一张
取 消