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:];

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的更多相关文章

  1. NSString、NSMutableString基本用法

    NSString其实是一个对象类型.NSString是NSObject(Cocoa Foundation的基础对象)的子类 一.NSString的创建 1.创建常量字符串.NSString *astr ...

  2. NSString的常见方法

    //1.创建常量字符串. NSString *astring = @"This is a String!";   //2.创建空字符串,给予赋值. NSString *astrin ...

  3. iOS NSString的常用用法

    //1.创建常量字符串. NSString *astring = @"This is a String!";   //2.创建空字符串,给予赋值. NSString *astrin ...

  4. NSString 截取字符串

    NSString字符串常用方法2010-09-06 14:18/******************************************************************** ...

  5. NSString、NSMutableString基本使用

    郝萌主倾心贡献.尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助.欢迎给作者捐赠,支持郝萌主.捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...

  6. NSString 练习

        //将“⽂文艺⻘青年”改成“213⻘青年”.   NSString *str = @"文艺青年";   NSString *str1 = [str stringByRepl ...

  7. NSString 字符串操作

    //一.NSString /*----------------创建字符串的方法----------------*/ //1.创建常量字符串. NSString *astring = @"Th ...

  8. NSString 用法大全。

    一.NSString 创建字符串.  NSString *astring = @"This is a String!"; 创建空字符串,给予赋值.  NSString *astri ...

  9. 转:用法总结:NSNumber、NSString、NSDate、NSCalendarDate、NSData(待续)

    NSNumber + (NSNumber *)numberWithInt:(int)value; + (NSNumber *)numberWithDouble:(double)value; - (in ...

随机推荐

  1. Web.config配置文件

    优点:Web.config配置文件使得ASP.NET应用程序的配置变得灵活高效和容易实现并为ASP.NET应用提供了可扩展的配置,使得应用程序能够自定义配置,同时还包括的优点有:配置设置易读性.更新的 ...

  2. c#获取多个List<class>合并、并将相同条件下的值累计sum

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. NetCat使用手册

    简介:   在网络工具中有“瑞士军刀”美誉的NetCat(以下简称nc),在我们用了N年了至今仍是爱不释手.因为它短小精悍(这个用在它身上很适合,现在有人已经将其修改成大约10K左右,而且功能不减少) ...

  4. Azkaban 作业调度

    转载一篇不错的文章:http://www.cnblogs.com/smartloli/p/5191155.html

  5. sublime配置问题

    sublime本身功能有限,我们需要装上一些插件使其变得强大.sublime在各个操作系统下都可以运行,但在linux下运行需要注意中文输入的问题. 下面我主要介绍一下常用插件.配置的建议以及在lin ...

  6. 菜鸟的js学习笔记

    学的越多感觉不会的越多.php+mysql学了点皮毛.知道搞web的是要会js的于是开始结合公司的项目开始学习js之旅(http://www.w3school.com.cn/b.asp) $(docu ...

  7. Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

    问题提示:Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace. ...

  8. python实现 _ 图书馆书籍到期之前_自动邮件提醒

    一共两个脚本: 第一个是[借书完毕以及借书信息有变更(续借等)]的时候需要执行的脚本:实现模拟登陆,同时最新的借书信息的下载到本地文本:之所以没有这样做,是因为如果每次爬取一遍的话,需要每次输入一遍验 ...

  9. django-url调度器-高级篇

    我们在中级篇中学会了如何进行反向解析,但是有这样一个问题,在为 url 命名的时候,名字不能重复,否则会导致各种各样的问题.在 url 还少的时候保证不重名还是比较简单的,但是 url 多起来以后就比 ...

  10. JForum二次开发(一)

    1.环境 myeclipse2014,jdk7,tomcat8,mysql5.6 2.下载源码地址 http://jforum.net/download.jsp 3.导入源码 新建web工程JForu ...