您的位置:首页 > 其它

How to insert a character into a NSString

2014-07-14 14:39 381 查看
How do I insert a space to a NSString.

I need to add a space at index 5 into:

NString * dir = @"abcdefghijklmno";

To get this result:

abcde fghijklmno

with:

NSLOG (@"%@", dir);


You need to use NSMutableString

[/code]

NSMutableString *mu = [NSMutableString stringWithString:dir];
[mu insertString:@" " atIndex:5];


or you could use those method to split your string :

– substringFromIndex:
– substringWithRange:
– substringToIndex:


and recombine them after with

– stringByAppendingFormat:
– stringByAppendingString:
– stringByPaddingToLength:withString:startingAtIndex:

http://stackoverflow.com/questions/8722051/how-to-insert-a-character-into-a-nsstring
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐