码迷,mamicode.com
首页 > 其他好文 > 详细

How to insert a character into a NSString

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

标签:style   blog   http   color   os   art   

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

标签:style   blog   http   color   os   art   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!