如何附加NSString的数字? [英] How to append NSString wiht number?

查看:118
本文介绍了如何附加NSString的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Cocoa的新人。



我有NSString - (例如)MUSIC。我想在Array中添加一些新的NSString,
并且想要检查这样



如果MUSIC已经包含在Array中,则在Music_2之后添加Music_1上。



所以我需要能够从NSString读取整数,并将其附加+1。



感谢

解决方案

使用

  NSString * newString = [myString stringByAppendingString:[NSString stringWithFormat:@_%i,myInteger]]; 

如果myString是music,newString将是music_1或任何myInteger。 >

编辑:我似乎得到了另一个答案提供的相反的意思。你能澄清一下你在问什么?


I'm new in Cocoa.

I have NSString - (e.g) MUSIC . I want to add some new NSString in Array, And want to check something like this

if MUSIC already contained in Array, add Music_1 , after Music_2 and so on.

So I need to be able read that integer from NSString, and append it +1 .

Thanks

解决方案

Use

NSString *newString = [myString stringByAppendingString:[NSString stringWithFormat:@"_%i", myInteger]];

if myString is "music", newString will be "music_1" or whatever myInteger is.

EDIT: I seem to have gotten the opposite meaning from the other answer provided. Can you maybe clarify what it is you are asking exactly?

这篇关于如何附加NSString的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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