//
// main.m
// OC5_NSMutableString操作
//
// Created by zhangxueming on 15/6/10.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h>
//NSMutableString 继承与NSString
//所有NSString类的方法NSMutableString 都可以使用 int main(int argc, const char * argv[]) {
@autoreleasepool {
//创建指定容量大小的可变字符串对象
//+ (NSMutableString *)stringWithCapacity:(NSUInteger)capacity;
NSMutableString *mulStr1 = [[NSMutableString alloc] initWithCapacity:];
NSLog(@"mulStr1 = %@", mulStr1); //替换指定范围内的字符
//- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString;
NSMutableString *mulStr2 = [[NSMutableString alloc] initWithString:@"hello world qianfeng"];
[mulStr2 replaceCharactersInRange:NSMakeRange(, ) withString:@"welcome"];
NSLog(@"mulStr2 = %@", mulStr2); //在指定位置增加字符串
NSMutableString *mulStr3 = [[NSMutableString alloc] initWithFormat:@"千锋中国"];
[mulStr3 insertString:@"hello world" atIndex:];
NSLog(@"mulStr3 = %@", mulStr3); //删除指定范围内的字符
NSMutableString *mulStr4 = [NSMutableString stringWithUTF8String:"千锋hello world中国"];
[mulStr4 deleteCharactersInRange:NSMakeRange(, )];
NSLog(@"mulStr4 = %@", mulStr4); //追加字符串
NSMutableString *mulStr5 = [NSMutableString stringWithString:@"helloworld"];
[mulStr5 appendString:@"qianfeng"];
NSLog(@"mulStr5 = %@", mulStr5); //格式化追加字符串
NSMutableString *mulStr6 = [NSMutableString stringWithFormat:@"%s%d", "hello", ];
[mulStr6 appendFormat:@"%.2f%@", 3.14, @"world"];
NSLog(@"mulStr6 = %@", mulStr6); //修改字符串
NSMutableString *mulStr7 = [[NSMutableString alloc] initWithString:@"hello world"];
[mulStr7 setString:@"qianfeng"];
NSLog(@"mulStr7 = %@", mulStr7); }
return ;
}

最新文章

  1. XAMARIN.ANDROID SIGNALR 实时消息接收发送示例
  2. mysql将一张表中多条记录按联系整合成一条
  3. GitHub使用指南
  4. HDU 2577
  5. Div的宽度与高度的100%设定
  6. 通过ros节点发布Twist Messages控制机器人--10
  7. Ubuntu 13.10 安装Qt5
  8. 问题-某个程序改了ICO图标后编译后还是显示老图标?
  9. 登陆与注册以及Session
  10. SEO_Alexa排名
  11. [置顶] Objective-C ,ios,iphone开发基础:在UITextField输入完以后,隐藏键盘,
  12. [C++程序设计]函数模板
  13. elasticsearch java和_head插件对索引文档的增删改查
  14. Calling LoadLibraryEx on ISAPI filter failed
  15. 使用Visual Studio 2017开发Linux程序
  16. zookeeper kafka集群
  17. php each和list的用法
  18. return的一种用法:如果当前判断为true则跳出这个方法。
  19. oracle 修改字符集 为ZHS16GBK
  20. 使用Cookie进行会话管理

热门文章

  1. Modbus调试利器 Modbus Poll
  2. hdu1863 畅通工程(最小生成树之prim)
  3. hdu 4612 (双联通+树形DP)
  4. [置顶] Objective-C ,ios,iphone开发基础:protocol 协议(委托,代理)的声明
  5. java学习之路---线程(重点)
  6. Android AndroidManifest 清单文件以及权限具体解释
  7. android开发学习:打电话和发短信
  8. iOS开发——MVC详解&amp;Swift+OC
  9. 【C语言】字符串替换空格:实现一个函数,把字符串里的空格替换成“%20”
  10. js之createTextRange方法