objective-C语言_对可变字符串操作的常用方法
来源:互联网 发布:windows tasksche.exe 编辑:程序博客网 时间:2024/06/05 04:36
#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { //可变字符串 NSMutableString NSMutableString *mString = [NSMutableString stringWithString:@"nihao"]; NSMutableString *mString1 = [NSMutableString stringWithFormat:@"hello%d",100]; //从本地读取文件 NSMutableString *mString2 = [NSMutableString stringWithContentsOfFile:@"" encoding:NSUTF8StringEncoding error:nil]; NSURL *url = [NSURL URLWithString:@""]; NSMutableString *mString3 = [NSMutableString stringWithContentsOfURL:url encoding:4 error:nil]; //可变字符串独特初始化方法,初始化一个空间为100的可变字符串 NSMutableString *mString4 = [[NSMutableString alloc]initWithCapacity:100]; //C语言的字符数组转成OC的字符串// [[NSString alloc]initWithCharacters:<#(nonnull const unichar *)#> length:<#(NSUInteger)#>] NSMutableString *targetString = [NSMutableString stringWithString:@"呵呵,我靠"]; NSRange range = [targetString rangeOfString:@"靠"]; NSLog(@"%@",[NSValue valueWithRange:range]); //替代 [targetString replaceCharactersInRange:range withString:@"*"]; NSLog(@"targetString = %@",targetString); //增加 //在指定位置去插入一个字符串 [targetString insertString:@"你是sb么" atIndex:targetString.length]; NSLog(@"targetString = %@",targetString); //在字符串的末尾添加一个字符串 [targetString appendString:@",byebye"]; NSLog(@"targetString = %@",targetString); [targetString appendFormat:@"%@%@",@",your mother",@"boom boom"]; NSLog(@"targetString = %@",targetString); //删除 [targetString deleteCharactersInRange:NSMakeRange(0, 3)]; NSLog(@"%@",targetString); } return 0;}
0 0
- Objective-c语言_对可变字符串操作的常用方法
- objective-C语言_对可变字符串操作的常用方法
- Objective-c语言_对字符串操作的常用方法
- Objective-C语言_对字符串操作的常用方法
- Objective-c语言_对可变数组NSMutableArray
- Objective-C 可变字符串操作
- Objective-C 可变字符串操作
- 【Objective-C】OC中可变字符串(NSMutableString)常用方法
- 关于Objective-C中常用的操作字符串的方法
- Objective-c语言_可变字典
- Objective-C语言_可变字典
- Objective-C 对字符串的操作
- Objective-c的字符串的常用操作
- C常用的对字符串操作的几个方法
- Objective-c 常用字符串操作
- Objective-C 的可变字符串 NSMutableString
- Objective-c语言_文件基本操作
- C语言对字符串的操作
- Ubuntu15.04 C语言操作Redis
- 浅析计算机网络(2) -- DNS工作原理
- 简单逆向分析使用案例(7)--Reverse001.exe 获取密码
- spring框架详解视频
- Spring Security3 - MVC 整合教程 (初识Spring Security3)
- objective-C语言_对可变字符串操作的常用方法
- 在Eclipse中启动Tomcat异常, unable to start within 45
- 第一章 在Centos7.1上安装oracle11gR2-图形化安装
- android 外部启动activity,自定义action,action常量大全
- 在spring中读取properties配置文件里面的信息
- 经验技巧
- CRLF、LF、CR
- SLF4J 簡介
- Android 缩略图