首页 > 代码库 > iOS 基础类解析 - NSString
iOS 基础类解析 - NSString
iOS 基础类解析 - NSString
太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)
本文遵循“署名-非商业用途-保持一致”创作公用协议
转载请保留此句:太阳火神的美丽人生 - 本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
以下从苹果官网摘录的 NSString 的目录信息,大家发现了,条目太多,不过看一下分类,一共24个,好像少很多了吧,就是这样,理解了每一个分类所要做的事情和做事情的原则,那么再具体到由哪一个方法来做,就没那么重要了,苹果的方法重载与 C++/Java 不太一样,但那只是表面形式的不同,本质是一样的,都是 面向对象/基于对象 的那些基本特点:重载、多态、继承、封装,还有一些原则,比如对修改封闭,对扩展开放,等等...!
接下来,24类看着也有点多,我再帮初学者们扎腾扎腾,你就会发现,这些看似一堆 一堆 的东西,变得条理清晰,也没那么让人头疼了。
NSString 类参考
NSString Class Reference
继承自 Inherits from | NSObject |
遵循的协议 Conforms to | NSCopying NSMutableCopying NSSecureCoding NSObject (NSObject) |
所在框架 Framework | /System/Library/Frameworks/Foundation.framework |
可用于的 iOS 版本 Availability | Available in iOS 2.0 and later. |
声明于头文件 Declared in | NSLinguisticTagger.h NSPathUtilities.h NSString.h NSURL.h |
配套的开发指南 Companion guides | String Programming Guide Property List Programming Guide |
AdvancedURLConnections AirDrop Examples BonjourWeb MVCNetworking TableView Fundamentals for iOS |
1、创建和初始化字符串
Creating and Initializing Strings
+ string
– init
– initWithBytes:length:encoding:
– initWithBytesNoCopy:length:encoding:freeWhenDone:
– initWithCharacters:length:
– initWithCharactersNoCopy:length:freeWhenDone:
– initWithString:
– initWithCString:encoding:
– initWithUTF8String:
– initWithFormat:
– initWithFormat:arguments:
– initWithFormat:locale:
– initWithFormat:locale:arguments:
– initWithData:encoding:
+ stringWithFormat:
+ localizedStringWithFormat:
+ stringWithCharacters:length:
+ stringWithString:
+ stringWithCString:encoding:
+ stringWithUTF8String:
+ stringWithCString:
Deprecated in iOS 2.0+ stringWithCString:length:
Deprecated in iOS 2.0– initWithCString:
Deprecated in iOS 2.0– initWithCString:length:
Deprecated in iOS 2.0– initWithCStringNoCopy:length:freeWhenDone:
Deprecated in iOS 2.0
2、从一个文件创建和初始化字符串
Creating and Initializing a String from a File
+ stringWithContentsOfFile:encoding:error:
– initWithContentsOfFile:encoding:error:
+ stringWithContentsOfFile:usedEncoding:error:
– initWithContentsOfFile:usedEncoding:error:
+ stringWithContentsOfFile:
Deprecated in iOS 2.0– initWithContentsOfFile:
Deprecated in iOS 2.0
3、从一个 URL 创建和初始化字符串
Creating and Initializing a String from an URL
+ stringWithContentsOfURL:encoding:error:
– initWithContentsOfURL:encoding:error:
+ stringWithContentsOfURL:usedEncoding:error:
– initWithContentsOfURL:usedEncoding:error:
+ stringWithContentsOfURL:
Deprecated in iOS 2.0– initWithContentsOfURL:
Deprecated in iOS 2.0
4、将字符串内容写到文件或 URL
Writing to a File or URL
– writeToFile:atomically:encoding:error:
– writeToURL:atomically:encoding:error:
– writeToFile:atomically:
Deprecated in iOS 2.0– writeToURL:atomically:
Deprecated in iOS 2.0
5、获取字符串长度
Getting a String’s Length
– length
– lengthOfBytesUsingEncoding:
– maximumLengthOfBytesUsingEncoding:
6、获取字符和字节
Getting Characters and Bytes
– characterAtIndex:
– getCharacters:range:
– getBytes:maxLength:usedLength:encoding:options:range:remainingRange:
– getCharacters:
Deprecated in iOS 4.0
7、获取 C 字符串
Getting C Strings
– cStringUsingEncoding:
– getCString:maxLength:encoding:
– UTF8String
– cString
Deprecated in iOS 2.0– cStringLength
Deprecated in iOS 2.0– getCString:
Deprecated in iOS 2.0– getCString:maxLength:
Deprecated in iOS 2.0– getCString:maxLength:range:remainingRange:
Deprecated in iOS 2.0– lossyCString
Deprecated in iOS 2.0
8、拼接字符串
Combining Strings
– stringByAppendingFormat:
– stringByAppendingString:
– stringByPaddingToLength:withString:startingAtIndex:
9、拆分字符串
Dividing Strings
– componentsSeparatedByString:
– componentsSeparatedByCharactersInSet:
– stringByTrimmingCharactersInSet:
– substringFromIndex:
– substringWithRange:
– substringToIndex:
10、查找字符和子字符串
Finding Characters and Substrings
– rangeOfCharacterFromSet:
– rangeOfCharacterFromSet:options:
– rangeOfCharacterFromSet:options:range:
– rangeOfString:
– rangeOfString:options:
– rangeOfString:options:range:
– rangeOfString:options:range:locale:
– enumerateLinesUsingBlock:
– enumerateSubstringsInRange:options:usingBlock:
11、替换字符串
Replacing Substrings
– stringByReplacingOccurrencesOfString:withString:
– stringByReplacingOccurrencesOfString:withString:options:range:
– stringByReplacingCharactersInRange:withString:
12、确定行和段落的范围
Determining Line and Paragraph Ranges
– getLineStart:end:contentsEnd:forRange:
– lineRangeForRange:
– getParagraphStart:end:contentsEnd:forRange:
– paragraphRangeForRange:
13、确定组成字符的顺序*
Determining Composed Character Sequences
– rangeOfComposedCharacterSequenceAtIndex:
– rangeOfComposedCharacterSequencesForRange:
14、将字符串内容转换成属性列表
Converting String Contents Into a Property List
– propertyList
– propertyListFromStringsFileFormat
15、识别和比较字符串
Identifying and Comparing Strings
– caseInsensitiveCompare:
– localizedCaseInsensitiveCompare:
– compare:
– localizedCompare:
– compare:options:
– compare:options:range:
– compare:options:range:locale:
– localizedStandardCompare:
– hasPrefix:
– hasSuffix:
– isEqualToString:
– hash
16、拆叠字符串*
Folding Strings
– stringByFoldingWithOptions:locale:
17、获取公共的前缀
Getting a Shared Prefix
– commonPrefixWithString:options:
18、改变大小写
Changing Case
– capitalizedString
– capitalizedStringWithLocale:
– lowercaseString
– lowercaseStringWithLocale:
– uppercaseString
– uppercaseStringWithLocale:
19、使用映射获取多个字符串*
Getting Strings with Mapping
– decomposedStringWithCanonicalMapping
– decomposedStringWithCompatibilityMapping
– precomposedStringWithCanonicalMapping
– precomposedStringWithCompatibilityMapping
20、获取数字值
Getting Numeric Values
– doubleValue
– floatValue
– intValue
– integerValue
– longLongValue
– boolValue
21、处理字符编码
Working with Encodings
+ availableStringEncodings
+ defaultCStringEncoding
+ localizedNameOfStringEncoding:
– canBeConvertedToEncoding:
– dataUsingEncoding:
– dataUsingEncoding:allowLossyConversion:
– description
– fastestEncoding
– smallestEncoding
22、处理路径
Working with Paths
+ pathWithComponents:
– pathComponents
– completePathIntoString:caseSensitive:matchesIntoArray:filterTypes:
– fileSystemRepresentation
– getFileSystemRepresentation:maxLength:
– isAbsolutePath
– lastPathComponent
– pathExtension
– stringByAbbreviatingWithTildeInPath
– stringByAppendingPathComponent:
– stringByAppendingPathExtension:
– stringByDeletingLastPathComponent
– stringByDeletingPathExtension
– stringByExpandingTildeInPath
– stringByResolvingSymlinksInPath
– stringByStandardizingPath
– stringsByAppendingPaths:
23、处理 URL
Working with URLs
– stringByAddingPercentEscapesUsingEncoding:
– stringByReplacingPercentEscapesUsingEncoding:
– stringByAddingPercentEncodingWithAllowedCharacters:
– stringByRemovingPercentEncoding
24、语言标记和分析*
Linguistic Tagging and Analysis
– enumerateLinguisticTagsInRange:scheme:options:orthography:usingBlock:
– linguisticTagsInRange:scheme:options:orthography:tokenRanges:
Copyright ? 2014 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2014-02-11
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。