iOS 基础类解析 - NSString、NSMutableString
iOS 基础类解析 - NSString
太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es)
本文遵循“署名-非商业用途-保持一致”创作公用协议
下面从苹果官网摘录的 NSString 的文件夹信息,大家发现了,条目太多。只是看一下分类,一共24个。好像少非常多了吧,就是这样,理解了每个分类所要做的事情和做事情的原则,那么再详细到由哪一个方法来做,就没那么重要了,苹果的方法重载与 C++/Java 不太一样。但那仅仅是表面形式的不同,本质是一样的,都是 面向对象/基于对象 的那些基本特点:重载、多态、继承、封装,另一些原则。比方对改动封闭,对扩展开放。等等...!
接下来,24类看着也有点多。我再帮刚開始学习的人们扎腾扎腾,你就会发现,这些看似一堆 一堆 的东西,变得条理清晰。也没那么让人头疼了。
NSString 类參考
NSString Class Reference
|
继承自 Inherits from |
|
|
遵循的协议 Conforms to |
|
|
所在框架 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 |
|
|
相关的演示样例代码 Related sample code |
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
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– cStringDeprecated
in iOS 2.0– cStringLengthDeprecated
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– lossyCStringDeprecated
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
14、将字符串内容转换成属性列表
Converting String Contents Into a Property List
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
17、获取公共的前缀
Getting a Shared Prefix
18、改变大写和小写
Changing Case
– capitalizedString– capitalizedStringWithLocale:– lowercaseString– lowercaseStringWithLocale:– uppercaseString– uppercaseStringWithLocale:
19、使用映射获取多个字符串*
Getting Strings with Mapping
– decomposedStringWithCanonicalMapping– decomposedStringWithCompatibilityMapping– precomposedStringWithCanonicalMapping– precomposedStringWithCompatibilityMapping
20、获取数字值
Getting Numeric Values
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
Copyright © 2014 Apple Inc. All Rights Reserved. Terms of Use | Privacy
Policy | Updated: 2014-02-11
iOS 基础类解析 - NSString、NSMutableString的更多相关文章
- iOS 基础类解析 - NSDate
版权声明:本文为博主原创文章,未经博主同意不得转载.转载联系 QQ 30952589,加好友请注明来意. https://blog.csdn.net/sleks/article/details/248 ...
- iOS 基础类解析 - NSData、NSMutableData
iOS 基础类解析 - NSData.NSMutableData 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致& ...
- iOS中解析 XML / JSON
JSON数据格式 1. 概述: JSON (JavaScript Object Notation) 是⼀一种轻量级的数据交换格式 基于⽂文本格式,易于⼈人阅读和编写,同时也易于机器解析和⽣生成. 2. ...
- IOS 原生解析JSON 问题
服务器----WebService 返回的是JSON数据 IOS解析报错: Error Domain=NSCocoaErrorDomain Code=3840 "Unable to conv ...
- NSString&NSMutableString常用操作梳理
http://www.cocoachina.com/ios/20150724/12722.html 上一篇梳理了NSArray&NSMutableArray常用操作,这次来梳理一下Object ...
- 【译】UI设计基础(UI Design Basics)--iOS应用解析(iOS App Anatomy)(三)
2.1 iOS应用解析(iOS App Anatomy) 几乎所有的iOS应用都会用到UIKit框架中的组件.了解这些基础组件的名称,角色,功能可以帮你在应用界面设计时做出更好的决策. UIKit提 ...
- NSString&NSMutableString常用操作梳理(转)
作者:弦苦 授权本站转载. 上一篇梳理了NSArray&NSMutableArray常用操作,这次来梳理一下Objective-C中每天都要用到的字符串处理类——NSString. Objec ...
- IOS 文件解析
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java ...
- iOS书摘之Objective-C编程之道 iOS设计模式解析
来自<Objective-C编程之道iOS设计模式解析>一书的摘要总结 一.Prototype 原型模式 定义:使用原型实例指定创建对象的种类,并通过复制这个原型创建新的对象.(<设 ...
随机推荐
- android fragment轻松监听返回键/Fragment中的popupwindow响应返回键隐藏
现在的开发我们基本上都是一个主activity中放多个fragment,点击返回按钮的时候,直接退出主activity,但是我们在fragment中经常会弹出例如popupWindow这样的布局,用户 ...
- C# winform启动外部exe后,如何完全阻断父界面接收事件,扩展waitforexit
公司的系统搭载了好多奇奇怪怪的exe,以前启动exe后,系统还能接着操作.但是后面又提出额外的需求,说是打开外部exe之后,启动exe的父界面要完全不能进行任何操作.当然按常人所想再加一句waitfo ...
- (转)分布式文件存储FastDFS(四)配置fastdfs-apache-module
http://blog.csdn.net/xingjiarong/article/details/50560605 在前边我们已经配置好了FastDFS的环境,但是此时的FastDFS还不能通过htt ...
- 如何知道自己的CPU支持SLAT
因为WP8 SDK发布,很多WP8的开发者们也开始陆续安装WP8的SDK的,然而安装WP8的SDK有很多软件和硬件的要求,其中有一个就是——要求CPU支持二级地址转换(SLAT),如果CPU不支持二级 ...
- Discuz 首页图文列表实现
<div id="shoucang"> <!--{eval $list_count=0;}--> <!--{loop $threadlist $thr ...
- Django - 一对多数据示例
1.增加Host -id 可以在模版中增加代码: 备注: 1.counter (从1开始) 2.counter0(从0开始) 3.revcounter(倒序) 4.revcounter0(倒序从0开始 ...
- B.1 接口
几乎所有要学习的接口都位于 System.Collections.Generic 命名空间.图B-1展示了.NET4.5以前主要接口间的关系,此外还将非泛型的 IEnumerable 作为根接口包括了 ...
- python爬虫12 | 爸爸,他使坏,用动态的 Json 数据,我要怎么搞?
在前面我们玩了好多静态的 HTML 想必你应该知道怎么去爬这些数据了 但还有一些常见的动态数据 比如 商品的评论数据 实时的直播弹幕 岛国动作片的评分 等等 这些数据是会经常发生改变的 很多网站就会用 ...
- BZOJ 3732 Network 【模板】kruskal重构树
[题解] 首先,我们可以发现,A到B的所有路径中,最长边的最小值一定在最小生成树上.我们用Kruskal最小生成树时,假设有两个点集U,V,若加入一条边w(u,v)使U,V联通,那么w就是U中每个点到 ...
- hdu 5179 beautiful number
beautiful number 问题描述 令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑i=1nai∗10n−i ...