首页 > 其他 > 详细

How to insert a character into a NSString

时间:2014-07-14 21:12:46      阅读:245      评论:0      收藏:0      [点我收藏+]

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

How to insert a character into a NSString,布布扣,bubuko.com

How to insert a character into a NSString

原文:http://www.cnblogs.com/savagemorgan/p/3842681.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!