Repository navigation
Scanners
binism edited this page May 1, 2016
·
9 revisions
一个NSScanner对象扫描NSString对象的字符,并代表性地解释字符,将它们转换为数字或字符串值。你在创建的同时指定了scanner的字符串,按照你的要求,scanner将会由始至终地对整个串的字符进行处理。
对象NSScanner是一个拥有public类NSSscanner的类簇。通常情况下,你可以通过该对象的类方法scannerWithString:或localizedScannerWithString:来实例化一个Scanner对象。无论使用哪一种方法,都会返回一个由你传入的字符串初始化的scanner对象。新建的Scanner在字符串的开头开始。你可以使用scan...方法来扫描(字符串)成分(components),比如使用scanInt:,scanDouble:和scanString:intoString:。如果需要扫描多次,通常可以创建一个while循环,让它扫描至字符串结尾,如下代码段所示:
float aFloat;
NSScanner *theScanner = [NSScanner scannerWithString:aString];
while ([theScanner isAtEnd] == NO) {
[theScanner scanFloat:&aFloat];
// implementation continues...
}你可以使用setCaseSensitive:方法来配置scanner使它考虑或忽视大小写。
- Introduction
- Strings
- Creating and Converting String Objects
- Formatting String Objects
- String Format Specifiers
- Reading Strings From and Writing Strings To Files and URLs
- Searching, Comparing, and Sorting Strings
- Words, Paragraphs, and Line Breaks
- Characters and Grapheme Clusters
- Character Sets
- Scanners
- String Representations of File Paths
- Drawing Strings
- Document Revision History
- Index