开发者

How to add an integer into String using objective c?

开发者 https://www.devze.com 2022-12-23 16:20 出处:网络
I am a java programmer, I found that Java is very good at doing string. If I want to do this objective c, how can I do in objective c ?

I am a java programmer, I found that Java is very good at doing string.

If I want to do this objective c, how can I do in objective c ?

System.out.println("This is a 开发者_JS百科" + 123 + " test");


To place an integer into a string, you can do this:

int n = 123;
NSString *s = [NSString stringWithFormat:@"This is a %d test", n];

There are numerous other ways. But concatenating strings with integers by + operator is not one of them. :)


To place an integer into a string, you can do this:

int number = 123;
NSString *string = [NSString stringWithFormat:@"This is a %i test", number];

Or if you want to NSLog you have to do this :

int number = 123;
NSLog(@"This is a %i test", number);

It is very EASY !!!

0

精彩评论

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