常用类---字符串
来源:互联网 发布:淘宝评价可以改差评吗 编辑:程序博客网 时间:2024/05/21 10:58
字符串:NSString、NSMutableString
1. 创建:
NSString *s = @"123";
NSString *s = [[NSString alloc] initWithFormat:@"123%@", @"123"];
2. 格式转化:
double d = [s floatValue];
int i = [s intVlue];
3. 长度:
int lenght = [s lenght];
4. 比较:
BOOL b = [s1 isEqualToString:s2];
区分大小写的比较:
BOOL b = ( [ s1 caseInsensitiveCompare:s2 ] == NSOrderSame);
5. 大小写转换:
s = [ s1 uppercaseString ];
s = [ s1 lowercase String ];
6. 删除空白:
s = [ s1 stringByTrimmingCharactersInset: [ NSCharacterSet whitespaceCharacterSet]];
7. 截取字符串:
s = [s substringToIndex: index]; // s = 0--(index-1)
s = [s substringWithRange:[NSMakeRange(start, end)]];
s = [s substringFromIndex: index ] ; // s = index -- (length -1)
8. 替换:
s = [ s stringByReplacingOccurencesOfString:subS1 withString:subS2 ];
9. 组合:
s = [s1 stringAppendingString:s2];
10. 是否包含:
BOOL b = ( [s rangeOfString:subS].location != NSNotFound);
11. 取文件内容:
s = [NSString stringWithContentsOfFile: filenameString];
12. 取文件扩展名:
s = [fileNameString pathExtension];
13. 读取URL内容:
s = [NSString stringWithContentsOfURL:url];
- 常用类---字符串
- 常用字符串类库
- java常用类--字符串
- Java字符串常用类
- 字符串与常用类
- 常用的控制字符串类
- 常用类封装--随机字符串
- 常用的QString字符串类
- 常用字符串时间工具类
- JAVA常用字符串工具类
- 常用类库—--字符串
- 常用类之字符串String
- 常用的字符串工具类
- 常用字符串
- Java常用类:字符串相关类
- [转]常用的方法(字符串类)
- 一个Java的字符串常用类
- 总结-处理字符串常用方法类
- 零月高考试题猜想,让人有一种幸福的感觉
- 人际关系种种
- 我对作家的理解
- CSDN学生大本营的一道题
- C语言宏定义详解
- 常用类---字符串
- CSS兼容性---测试笔记
- PIMPL IDIOM & FAST PIMPL
- Es muss sein!!!
- 超简单的Erlang复数实现
- VS2008 with GLUT
- SAP 开发介绍之 R3开发平台
- Expression Blend实例中文教程(7) - 动画基础快速入门Animation
- Derby入门