#pragma mark 可变字符串的创建
void stringCreate() {
// 预先分配10个字数的存储空间
NSMutableString *str = [[NSMutableString alloc] initWithCapacity:];
// 设置字符串内容
[str setString:@""]; // 拼接一个字符串
[str appendString:@""];
// 拼接字符串
[str appendFormat:@"age is %i and height is %.2f", , 1.55f]; // 替换字符串
NSRange range = [str rangeOfString:@"height"];
//NSRange range = NSMakeRange(7, 3);
[str replaceCharactersInRange:range withString:@"no"]; // 插入字符串
[str insertString:@"abc" atIndex:]; // 删除字符串
range = [str rangeOfString:@"age"];
[str deleteCharactersInRange:range]; NSLog(@"%@", str); // 释放对象
[str release];
} int main(int argc, const char * argv[])
{
@autoreleasepool {
stringCreate();
}
return ;
}

OC NSMutableString的使用的更多相关文章

  1. OC第二节 —— NSString和NSMutableString

    1.为什么需要NSString对象        答:在OC中创建字符串时,一般不使用C的方法,    因为C将字符串作为字符数组,所以在操作时会有很多不方便的地方,    在Cocoa中NSStri ...

  2. (转载)OC学习篇之---Foundation框架中的NSString对象和NSMutableString对象

    在之前的一篇文章中我们说到了Foundation框架中的NSObject对象,那么今天在在来继续看一下Foundation框架中的常用对象:NSString和NSMutableString. 在OC中 ...

  3. OC之字符串 NSString与NSMutableString

    一.NSString 不可变字符串的操作1)将字符串常量对象直接赋值给字符串引用 NSString *str1=@"hello"; 字符串对象的输出格式:NSLog(@" ...

  4. OC本学习笔记Foundation框架NSString与NSMutableString

       一.NSString与NSMutableString         相信大家对NSString类都不陌生.它是OC中提供的字符串类.它的对象中的字符串都是不可变的,而它的子类NSMutable ...

  5. OC中Foundation框架之NSString、NSMutableString

    创建方式 )直接赋值 NSString *str =@"abc"; )创建对象 NSString *str2 = [[NSString alloc]init]; str2 =@&q ...

  6. OC学习篇之---Foundation框架中的NSString对象和NSMutableString对象

    今天在在来继续看一下Foundation框架中的常用对象:NSString和NSMutableString 在OC中NSString对象是不可变的,和Java中的String一样的,而NSMutabl ...

  7. OC之NSString、NSMutableString学习笔记 常用方法

    NSString篇: 1.字符串连接 NSString *beijing = @"北京"; NSString *welcome = [beijing stringByAppendi ...

  8. [OC Foundation框架 - 6] NSMutableString

    NSString是不可变的 NSMutableString是可变字符串   1.初始化 2.串联字符串 3.替换字符串 4.插入字符串 5.删除字符串   #pragma mark buffer st ...

  9. OC——NSString和NSMutableString

    int main(int argc, const char * argv[]) { @autoreleasepool { //----------------NSString------------- ...

随机推荐

  1. Django的学习基础1

    著名的MVC模式:所谓MVC就是把web应用分为模型(M),控制器(C),视图(V)三层:他们之间以一种插件似的,松耦合的方式连接在一起. Django的MTV模式本质上与MVC模式没有什么差别,也是 ...

  2. net 记录controller Action耗时

    可能有些时候需要记录Action的执行时间来优化系统功能,这时可以用过滤器来实现 第1个例子 using System; using System.Diagnostics; using System. ...

  3. sql语句将身份证号数字转换成特殊字符

    SELECT Tname , STUFF(Idcard,,,'*********') as Idcard,Completion from demo

  4. 在 Azure WebApps 中运行64位 Asp.net Core 应用

    作为微软下一代的开源的跨平台的开发框架, Asp.net core 正在吸引越来越多的开发者基于其构建现代 web 应用. 目前, Azure App Service 也实现了对 asp.net co ...

  5. CentOS7 一键安装KMS服务【整理】

    KMS,是 Key Management System 的缩写,也就是密钥管理系统.这里所说的 KMS,毋庸置疑就是用来激活 VOL 版本的 Windows 和 Office 的 KMS 啦.经常能在 ...

  6. getElementsByName属性

    getElementsByName() 方法可返回带有指定名称的对象的集合 语法 document.getElementsByName(name) 该方法与 getElementById() 方法相似 ...

  7. mac通过wine运行windows程序(将文件关联到windows程序notepad++)

    windows程序功能强大且已经习惯使用了,用mac总感觉不给力,例如记事本工具Notepad++就非常优秀.下面介绍如何在mac系统下通过wine来安装使用notepadd++程序. 1.安装win ...

  8. hdu 3466 Proud Merchants 01背包变形

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  9. IIS6服务器的请求流程(图文&源码)

    1.IIS 7开发与管理完全参考手册  http://book.51cto.com/art/200908/146040.htm 2.Web服务IIS 6   https://technet.micro ...

  10. 怎么让div显示一行,其余的隐藏。

    <style> div{ white-space: nowrap; text-overflow:ellipsis; text-overflow: ellipsis; overflow:hi ...