NSCharacter​Set 和 NSMutableCharacterSet  用面向对象的方式来表示一组Unicode字符,它经常与NSString及NSScanner组合起来使用,在不同的字符上做过滤、删除或者分割操作。为了给你提供这些字符是哪些字符的直观印象,请看看NSCharacterSet 提供的类方法

  • alphanumericCharacterSet
  • capitalizedLetterCharacterSet
  • controlCharacterSet
  • decimalDigitCharacterSet
  • decomposableCharacterSet
  • illegalCharacterSet
  • letterCharacterSet
  • lowercaseLetterCharacterSet
  • newlineCharacterSet
  • nonBaseCharacterSet
  • punctuationCharacterSet
  • symbolCharacterSet
  • uppercaseLetterCharacterSet
  • whitespaceAndNewlineCharacterSet
  • whitespaceCharacterSet

我们使用下边的方法 打印看看这些方法

 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[:]

不难看出,对字符串的过滤非常灵活,因此我们应该使用这种方法来过滤字符串。

NSCharacter​Set 使用说明的更多相关文章

  1. Atitit.项目修改补丁打包工具 使用说明

    Atitit.项目修改补丁打包工具 使用说明 1.1. 打包工具已经在群里面.打包工具.bat1 1.2. 使用方法:放在项目主目录下,执行即可1 1.3. 打包工具的原理以及要打包的项目列表1 1. ...

  2. awk使用说明

    原文地址:http://www.cnblogs.com/verrion/p/awk_usage.html Awk使用说明 运维必须掌握的三剑客工具:grep(文件内容过滤器),sed(数据流处理器), ...

  3. “我爱背单词”beta版发布与使用说明

    我爱背单词BETA版本发布 第二轮迭代终于画上圆满句号,我们的“我爱背单词”beta版本已经发布. Beta版本说明 项目名称 我爱背单词 版本 Beta版 团队名称 北京航空航天大学计算机学院  拒 ...

  4. Oracle 中 union 和union all 的简单使用说明

    1.刚刚工作不久,经常接触oracle,但是对oracle很多东西都不是很熟.今天我们来了解一下union和union all的简单使用说明.Union(union all): 指令的目的是将两个 S ...

  5. Map工具系列-02-数据迁移工具使用说明

    所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...

  6. Map工具系列-03-代码生成BySQl工具使用说明

    所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...

  7. jQuery验证控件jquery.validate.js使用说明

    官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...

  8. gdbsever 使用说明

    gdbsever 使用说明 在新塘N3292x平台下 编译 gdbsever ./configure --target=arm-linux --host=arm-linux arm-linux-gdb ...

  9. mongoVUE的增删改查操作使用说明

    mongoVUE的增删改查操作使用说明 一. 查询 1. 精确查询 1)右键点击集合名,再左键点击Find 或者直接点击工具栏上的Find 2)查询界面,包括四个区域 {Find}区,查询条件格式{& ...

随机推荐

  1. SQL Server 大数据搬迁之文件组备份还原实战

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 解决方案(Solution) 搬迁步骤(Procedure) 搬迁脚本(SQL Codes) ...

  2. 终于等到你:CYQ.Data V5系列 (ORM数据层)最新版本开源了

    前言: 不要问我框架为什么从收费授权转到免费开源,人生没有那么多为什么,这些年我开源的东西并不少,虽然这个是最核心的,看淡了就也没什么了. 群里的网友:太平说: 记得一年前你开源另一个项目的时候我就说 ...

  3. 实时的.NET程序错误监控产品Exceptionless

    Exceptionless可以对ASP.NET, Web API, WebForms, WPF, Console, 和 MVC 应用提供错误监控.上传.报表服务.使用时需要在Exceptionless ...

  4. 04.SQLServer性能优化之---读写分离&数据同步

    汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 过段时间再继续写文章吧,本来准备把SQLServer一个系列写完的,最近状态很差很不好, ...

  5. 伪共享(false sharing),并发编程无声的性能杀手

    在并发编程过程中,我们大部分的焦点都放在如何控制共享变量的访问控制上(代码层面),但是很少人会关注系统硬件及 JVM 底层相关的影响因素.前段时间学习了一个牛X的高性能异步处理框架 Disruptor ...

  6. jQuery学习之路(6)- 简单的表格应用

    ▓▓▓▓▓▓ 大致介绍 在CSS技术之前,网页的布局基本都是依靠表格制作,当有了CSS之后,表格就被很多设计师所抛弃,但是表格也有他的用武之地,比如数据列表,下面以表格中常见的几个应用来加深对jQue ...

  7. 多线程爬坑之路-Thread和Runable源码解析

    多线程:(百度百科借一波定义) 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提 ...

  8. 快递Api接口 & 微信公众号开发流程

    之前的文章,已经分析过快递Api接口可能被使用的需求及场景:今天呢,简单给大家介绍一下微信公众号中怎么来使用快递Api接口,来完成我们的需求和业务场景. 开发语言:Nodejs,其中用到了Neo4j图 ...

  9. node.js学习(二)--Node.js控制台(REPL)&&Node.js的基础和语法

    1.1.2 Node.js控制台(REPL) Node.js也有自己的虚拟的运行环境:REPL. 我们可以使用它来执行任何的Node.js或者javascript代码.还可以引入模块和使用文件系统. ...

  10. PHP 设计模式概述

    一.设计模式(Design pattern)是什么? 设计模式是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. ...