Savage F. Morgan

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

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

posted on 2014-07-14 14:39  罗斯摩根  阅读(213)  评论(0编辑  收藏  举报