NSCharacterSet 使用说明
NSCharacterSet 和 NSMutableCharacterSet 用面向对象的方式来表示一组Unicode字符,它经常与NSString及NSScanner组合起来使用,在不同的字符上做过滤、删除或者分割操作。为了给你提供这些字符是哪些字符的直观印象,请看看NSCharacterSet 提供的类方法
alphanumericCharacterSetcapitalizedLetterCharacterSetcontrolCharacterSetdecimalDigitCharacterSetdecomposableCharacterSetillegalCharacterSetletterCharacterSetlowercaseLetterCharacterSetnewlineCharacterSetnonBaseCharacterSetpunctuationCharacterSetsymbolCharacterSetuppercaseLetterCharacterSetwhitespaceAndNewlineCharacterSetwhitespaceCharacterSet
我们使用下边的方法 打印看看这些方法
void dumpCharacterSet( NSString *name )
{
unichar idx;
NSCharacterSet *cset = [NSCharacterSet performSelector: NSSelectorFromString(name)]; printf("Character set (0-127): %s\n7-Bit: ", [name UTF8String]); for( idx = ; idx < ; idx++ )
{
if ( == idx ) {
printf( "\n8-Bit: " );
} //Returns a Boolean value that indicates whether a given character is in the receiver.
if ([cset characterIsMember: idx])
{
//判断字符c是否为可打印字符(含空格)
if ( isprint(idx) ) {
printf( "%c ", idx);
}
else {
printf( "%02x ", idx);
}
}
}
printf("\n\n");
}
// Reference output...
dumpCharacterSet( @"alphanumericCharacterSet" );
dumpCharacterSet( @"controlCharacterSet" );
dumpCharacterSet( @"decimalDigitCharacterSet" );
dumpCharacterSet( @"decomposableCharacterSet" );
dumpCharacterSet( @"illegalCharacterSet" );
dumpCharacterSet( @"letterCharacterSet" );
dumpCharacterSet( @"lowercaseLetterCharacterSet" );
dumpCharacterSet( @"nonBaseCharacterSet" );
dumpCharacterSet( @"punctuationCharacterSet" );
dumpCharacterSet( @"uppercaseLetterCharacterSet" );
dumpCharacterSet( @"whitespaceAndNewlineCharacterSet" );
dumpCharacterSet( @"whitespaceCharacterSet" );
打印结果如下
Character set (-): alphanumericCharacterSet
-Bit: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z
-Bit: aa b2 b3 b5 b9 ba bc bd be c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f8 f9 fa fb fc fd fe ff Character set (-): controlCharacterSet
-Bit: 0a 0b 0c 0d 0e 0f 1a 1b 1c 1d 1e 1f 7f
-Bit: 8a 8b 8c 8d 8e 8f 9a 9b 9c 9d 9e 9f ad Character set (-): decimalDigitCharacterSet
-Bit:
-Bit: Character set (-): decomposableCharacterSet
-Bit:
-Bit: c0 c1 c2 c3 c4 c5 c7 c8 c9 ca cb cc cd ce cf d1 d2 d3 d4 d5 d6 d9 da db dc dd e0 e1 e2 e3 e4 e5 e7 e8 e9 ea eb ec ed ee ef f1 f2 f3 f4 f5 f6 f9 fa fb fc fd ff Character set (-): illegalCharacterSet
-Bit:
-Bit: Character set (-): letterCharacterSet
-Bit: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z
-Bit: aa b5 ba c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f8 f9 fa fb fc fd fe ff Character set (-): lowercaseLetterCharacterSet
-Bit: a b c d e f g h i j k l m n o p q r s t u v w x y z
-Bit: b5 df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f8 f9 fa fb fc fd fe ff Character set (-): nonBaseCharacterSet
-Bit:
-Bit: Character set (-): punctuationCharacterSet
-Bit: ! " # % & ' ( ) * , - . / : ; ? @ [ \ ] _ { }
-Bit: a1 a7 ab b6 b7 bb bf Character set (-): uppercaseLetterCharacterSet
-Bit: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
-Bit: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d8 d9 da db dc dd de Character set (-): whitespaceAndNewlineCharacterSet
-Bit: 0a 0b 0c 0d
-Bit: a0 Character set (-): whitespaceCharacterSet
-Bit:
-Bit: a0
非常的直观,当我们 使用的时候对照这个打印结果操作就行,
下边再说一下如何过滤的
// Set up for reading testString
NSString *testString = @"Los Angeles;8.25;0.580561574;1,Tokyo;1.9;0.643872234;1;Honolulu,0;0;0;Toronto;7.9;5.3322;3;";
// Parse CSV with NSScanner
NSScanner *myScanner = [NSScanner scannerWithString:testString]; NSString *location;
float theRevenue;
float thePercent;
int theRank; // Set up data delimiter using semicolon//分号 NSCharacterSet *CharacterSet; //Returns a character set containing the characters in a given string.
CharacterSet = [NSCharacterSet characterSetWithCharactersInString:@";,"]; // Double check scanner string
NSLog (@"Scanner string\n"); //Returns the string with which the receiver was created or initialized.
NSLog (@"%@",[myScanner string]); // scanner loop start
while ([myScanner isAtEnd] == NO) { if ( [myScanner scanUpToCharactersFromSet:CharacterSet intoString:&location] ) {
NSLog (@"%@",location);
} // Skipping the ; and ,delimiter
if([myScanner scanString:@";" intoString:NULL] || [myScanner scanString:@"," intoString:NULL])
;
// Read Revenue data up to ; delimiter and skipping
//Scans for a float value, returning a found value by reference.
if([myScanner scanFloat:&theRevenue])
NSLog(@"%lf",theRevenue);
if([myScanner scanString:@";" intoString:NULL] || [myScanner scanString:@"," intoString:NULL])
; // Read Percentage data up to ; delimiter and skipping
if([myScanner scanFloat:&thePercent])
NSLog(@"%lf",thePercent);
if([myScanner scanString:@";" intoString:NULL] || [myScanner scanString:@"," intoString:NULL])
; // Read Ranking data up to ; delimiter and skipping
if([myScanner scanInt:&theRank])
NSLog(@"%i",theRank);
if([myScanner scanString:@";" intoString:NULL] || [myScanner scanString:@"," intoString:NULL])
;
}
打印结果如下
-- ::37.967 ModelBenchmark[:] Los Angeles
-- ::37.967 ModelBenchmark[:] 8.250000
-- ::37.967 ModelBenchmark[:] 0.580562
-- ::37.968 ModelBenchmark[:]
-- ::37.968 ModelBenchmark[:] Tokyo
-- ::37.968 ModelBenchmark[:] 1.900000
-- ::37.968 ModelBenchmark[:] 0.643872
-- ::37.968 ModelBenchmark[:]
-- ::37.968 ModelBenchmark[:] Honolulu
-- ::37.968 ModelBenchmark[:] 0.000000
-- ::37.968 ModelBenchmark[:] 0.000000
-- ::37.968 ModelBenchmark[:]
-- ::37.968 ModelBenchmark[:] Toronto
-- ::37.968 ModelBenchmark[:] 7.900000
-- ::37.969 ModelBenchmark[:] 5.332200
-- ::37.969 ModelBenchmark[:]
不难看出,对字符串的过滤非常灵活,因此我们应该使用这种方法来过滤字符串。
NSCharacterSet 使用说明的更多相关文章
- Atitit.项目修改补丁打包工具 使用说明
Atitit.项目修改补丁打包工具 使用说明 1.1. 打包工具已经在群里面.打包工具.bat1 1.2. 使用方法:放在项目主目录下,执行即可1 1.3. 打包工具的原理以及要打包的项目列表1 1. ...
- awk使用说明
原文地址:http://www.cnblogs.com/verrion/p/awk_usage.html Awk使用说明 运维必须掌握的三剑客工具:grep(文件内容过滤器),sed(数据流处理器), ...
- “我爱背单词”beta版发布与使用说明
我爱背单词BETA版本发布 第二轮迭代终于画上圆满句号,我们的“我爱背单词”beta版本已经发布. Beta版本说明 项目名称 我爱背单词 版本 Beta版 团队名称 北京航空航天大学计算机学院 拒 ...
- Oracle 中 union 和union all 的简单使用说明
1.刚刚工作不久,经常接触oracle,但是对oracle很多东西都不是很熟.今天我们来了解一下union和union all的简单使用说明.Union(union all): 指令的目的是将两个 S ...
- Map工具系列-02-数据迁移工具使用说明
所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...
- Map工具系列-03-代码生成BySQl工具使用说明
所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...
- jQuery验证控件jquery.validate.js使用说明
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- gdbsever 使用说明
gdbsever 使用说明 在新塘N3292x平台下 编译 gdbsever ./configure --target=arm-linux --host=arm-linux arm-linux-gdb ...
- mongoVUE的增删改查操作使用说明
mongoVUE的增删改查操作使用说明 一. 查询 1. 精确查询 1)右键点击集合名,再左键点击Find 或者直接点击工具栏上的Find 2)查询界面,包括四个区域 {Find}区,查询条件格式{& ...
随机推荐
- mysql每秒最多能插入多少条数据 ? 死磕性能压测
前段时间搞优化,最后瓶颈发现都在数据库单点上. 问DBA,给我的写入答案是在1W(机械硬盘)左右. 联想起前几天infoQ上一篇文章说他们最好的硬件写入速度在2W后也无法提高(SSD硬盘) 但这东西感 ...
- 学点HTTP知识
不学无术 又一次感觉到不学无术,被人一问Http知识尽然一点也没答上来,丢人丢到家了啊.平时也看许多的技术文章,为什么到了关键时刻就答不上来呢? 确实发现一个问题,光看是没有用的,需要实践.看别人说的 ...
- 复杂的 Hash 函数组合有意义吗?
很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...
- javascript匹配各种括号书写是否正确
今天在codewars上做了一道题,如下 看上去就是验证三种括号各种嵌套是否正确书写,本来一头雾水,一种括号很容易判断, 但是三种怎么判断! 本人只是个前端菜鸟,,不会什么高深的正则之类的. 于是,在 ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- 手动导入swift三方danielgindi/Charts到OC工程中教程
1.到github网址上下载zip压缩包https://github.com/danielgindi/Charts 2.然后将解压后的文件夹整个拖到自己的工程文件夹下(很多教程只让拖xcodeproj ...
- Winserver2012下mysql 5.7解压版(zip)配置安装
一.安装 下载mysqlzip版本mysql不需要运行可执行文件,解压即可,下载zip版本mysqlmsi版本mysql双击文件即可安装,相对简单,本文不介绍此版本安装 配置环境变量打开环境变量配置页 ...
- Prometheus 系统监控方案 一
最近一直在折腾时序类型的数据库,经过一段时间项目应用,觉得十分不错.而Prometheus又是刚刚推出不久的开源方案,中文资料较少,所以打算写一系列应用的实践过程分享一下. Prometheus 是什 ...
- (整理)MyBatis入门教程(一)
本文转载: http://www.cnblogs.com/hellokitty1/p/5216025.html#3591383 本人文笔不行,根据上面博客内容引导,自己整理了一些东西 首先给大家推荐几 ...
- SpringMVC 数据校验
1.引入jar包 2.配置验证器 <!-- 配置验证器 --> <bean id="myvalidator" class="org.springfram ...