- Objective-C基础
- Objective-C - 首页
- Objective-C - 概述
- Objective-C - 环境设置
- Objective-C - 程序结构
- Objective-C - 基本语法
- Objective-C - 数据类型
- Objective-C - 变量
- Objective-C - 常量
- Objective-C - 运算符
- Objective-C - 循环
- Objective-C - 决策
- Objective-C - 函数
- Objective-C - 块
- Objective-C - 数字
- Objective-C - 数组
- Objective-C - 指针
- Objective-C - 字符串
- Objective-C - 结构体
- Objective-C - 预处理器
- Objective-C - Typedef
- Objective-C - 类型转换
- Objective-C - 日志处理
- Objective-C - 错误处理
- 命令行参数
- 高级Objective-C
- Objective-C - 类和对象
- Objective-C - 继承
- Objective-C - 多态
- Objective-C - 数据封装
- Objective-C - 分类
- Objective-C - 模拟
- Objective-C - 扩展
- Objective-C - 协议
- Objective-C - 动态绑定
- Objective-C - 组合对象
- Obj-C - Foundation框架
- Objective-C - 快速枚举
- Obj-C - 内存管理
- Objective-C有用资源
- Objective-C - 快速指南
- Objective-C -有用资源
- Objective-C - 讨论
Objective-C中的文本和字符串
NSString 是最常用的类之一,用于存储字符串和文本。如果您想了解更多关于 NSString 的信息,请参考 Objective-C 字符串中的 NSString。
如前所述,NSCharacterSet 表示 NSString 和 NSScanner 类使用的各种字符分组。
NSCharacterSet
以下是 NSCharacterSet 中可用的方法集,它们表示各种字符集。
alphanumericCharacterSet − 返回一个包含字母、标记和数字类别中字符的字符集。
capitalizedLetterCharacterSet − 返回一个包含标题大小写字母类别中字符的字符集。
characterSetWithCharactersInString − 返回一个包含给定字符串中字符的字符集。
characterSetWithRange − 返回一个包含给定范围内 Unicode 值的字符的字符集。
illegalCharacterSet − 返回一个包含非字符类别中的值或在 Unicode 3.2 标准中尚未定义的值的字符集。
letterCharacterSet − 返回一个包含字母和标记类别中字符的字符集。
lowercaseLetterCharacterSet − 返回一个包含小写字母类别中字符的字符集。
newlineCharacterSet − 返回一个包含换行符的字符集。
punctuationCharacterSet − 返回一个包含标点符号类别中字符的字符集。
symbolCharacterSet − 返回一个包含符号类别中字符的字符集。
uppercaseLetterCharacterSet − 返回一个包含大写字母和标题大小写字母类别中字符的字符集。
whitespaceAndNewlineCharacterSet − 返回一个包含 Unicode 通用类别 Z*、U000A ~ U000D 和 U0085 的字符集。
whitespaceCharacterSet − 返回一个仅包含内联空格字符空格 (U+0020) 和制表符 (U+0009) 的字符集。
#import <Foundation/Foundation.h>
int main() {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *string = @"....Tutorials Point.com.....";
NSLog(@"Initial String :%@", string);
NSCharacterSet *characterset = [NSCharacterSet punctuationCharacterSet];
string = [string stringByTrimmingCharactersInSet:characterset];
NSLog(@"Final String :%@", string);
[pool drain];
return 0;
}
现在,当我们编译并运行程序时,我们将得到以下结果。
2013-09-29 14:19:27.328 demo[687] Initial String :....Tutorials Point.com..... 2013-09-29 14:19:27.328 demo[687 Final String :Tutorials Point.com
我们在上面的程序中可以看到,给定字符串两侧的标点符号都被修剪掉了。这只是使用 NSCharacterSet 的一个例子。