如何在Objective-C(iPhone)中连接字符串? [英] How to Concatenate String in Objective-C (iPhone)?

查看:100
本文介绍了如何在Objective-C(iPhone)中连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在Objective-C中连接字符串?

首先,平台是iPhone,label.text更改显示的标签。考虑这种情况:

Firstly, the platform is iPhone and label.text changes the label displayed. Consider this scenario:

我有一个整数数组。我想在屏幕上显示它。

I've an array of integers. And I want to display it on the screen.

这是我的看法:

-(IBAction) updateText: (id)sender {
   int a[2];
   a[0]=1;
   a[1]=2;
   a[2]=3;
   for (int i=0; i<=10;i++)
     label.text = [NSString stringByAppendingString: [NSString stringWithFormat: @"%i", a[i]]]; 
}

正如你可能看到的,我很困惑。请帮我解决:(

As you can probably see, I'm pretty confused. Pls pls help me out :(

推荐答案

试试这个:

NSMutableString* theString = [NSMutableString string];
for (int i=0; i<=10;i++){
    [theString appendString:[NSString stringWithFormat:@"%i ",i]];
}
label.text = theString;

这篇关于如何在Objective-C(iPhone)中连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆