NSString
创建方式: (对象方法(对应类方法))
1. 针对不可变字符串: = @" ";
2.通过一个字符串创建 initWithString(stringWithString)
3 .通过格式化创建 initWithFormat(stringWithFormat)
常用属性
1.length
常用对象方法
1.取值(doubleValue,floatValue,intValue,integerValue)
2.大小写转化(uppercaseString,lowercaseString,capitalizedString)
3.拼接stringByAppendingString,Format,PathComponent
4.判断前后缀hasSuffix,hasPrefix
5.取字符串的内容substringFromIndex,substringToIndex,substringWithRange,characterIndex
字符串之间的交互:
6.比较大小(英文字典后面的大)compare __ options:__
7.是否相等:isEqualToString
8.查找 rangeOfString__ options:__
和其他类交互
1.字符串的分割与拼接(转化成数组)
componentsSeparatedByString,componentsSeparatedByCharactersInSet
(数组返回成字符串)componentsJoinedByString
2.其他
子类:可变字符串
增 append,insert
删 delete
改:set,replace
苹果官方文档学习(部分在这 全部请至官文文档查看)
class NSString
The NSString class and its mutable subclass, NSMutableString, provide an extensive set of APIs for working with strings, including methods for comparing, searching, and modifying strings. NSString objects are used throughout Foundation and other Cocoa frameworks, serving as the basis for all textual and linguistic functionality on the platform.
NSString类和可变的子类,NSMutableString,提供一个广泛的API集来处理字符串的方法,包括比较,搜索,修改字符串。NSString对象是整个基金会和其他的Cocoa框架的使用,为所有的文字和语言在平台功能的基础上。
Symbols
1.1 Creating and Initializing Strings(创建和初始化)
1.2 Creating and Initializing a String from a File(创建和初始化来源文件)
1.3 Creating and Initializing a String from an URL(创建和初始化来源URL)
1.4 Writing to a File or URL(写入一个文件或者URL)
1.5 Getting a String’s Length:
- length:The number of UTF-16 code units in the receiver.
- - lengthOfBytesUsingEncoding: Returns the number of bytes required to store the receiver in a given encoding.返回在给定编码中存储接收器所需的字节数。
- - maximumLengthOfBytesUsingEncoding: Returns the maximum number of bytes needed to store the receiver in a given encoding.返回在给定编码中存储接收器所需的最大字节数。
1.6 Getting Characters and Bytes:
1.7 Getting C Strings
1.8 Identifying and Comparing Strings(识别和比较NSString)
1.9 Combining Strings:(组合字符串)
- -stringByAppendingFormat:
- -stringByAppendingString:
- - stringByPaddingToLength:withString:startingAtIndex:
1.10 Dividing Strings:(分割字符串)
- - componentsSeparatedByString:
- - componentsSeparatedByCharactersInSet:
- - stringByTrimmingCharactersInSet:
- - substringFromIndex:
- - substringWithRange:
- - substringToIndex:
1.11 Finding Characters and Substrings(查找字符和子串)
- - containsString :
- -localizedCaseInsensitiveContainsString:
- -localizedStandardContainsString:
- -rangeOfCharacterFromSet:
- -rangeOfCharacterFromSet:options:
- -rangeOfCharacterFromSet:options:range:
- -rangeOfString:
- - rangeOfString:options:
- -rangeOfString:options:range:
- -rangeOfString:options:range:locale:
- -localizedStandardRangeOfString:
- -enumerateLinesUsingBlock:
- -enumerateSubstringsInRange:options:usingBlock:
1.12 Replacing Substrings(替换子字符串)
- - stringByReplacingOccurrencesOfString:withString:
- - stringByReplacingOccurrencesOfString:withString:options:range:
- - stringByReplacingCharactersInRange:withString:
1.13 Determining Line and Paragraph Ranges
1.14 Determining Composed Character Sequences
1.15 Converting String Contents Into a Property List
1.16 Drawing Strings
1.17 Folding Strings
1.18 Getting a Shared Prefix
1.19 Changing Case
1.20 Getting Strings with Mapping
1,21 Getting Numeric Values(doubleValue,floatValue,intValue,integerValue etc.)
1.22 Working with Encodings
1.23 Working with Paths
1.24 Working with URLs
1.25 Linguistic Tagging and Analysis
1.26 Deprecated(过时的)
1.27 Constants
1.28 Initializers . - initWithCoder:
1.29 Instance Methods
2 Relationships
2.1 Inherits From / NSObject (继承NSObject)
2.2 Conforms To / NSCopying, NSMutableCopying, NSSecureCoding (遵守这三个协议)
class NSMutableString
The NSMutableString class declares the programmatic interface to an object that manages a mutable string—that is, a string whose contents can be edited—that conceptually represents an array of Unicode characters. To construct and manage an immutable string—or a string that cannot be changed after it has been created—use an object of the NSString class.
NSMutableString类声明一个对象管理一个可变的字符串,字符串的编程接口,其内容可以被编辑,在概念上是一个Unicode字符数组。构建和管理一个不可变的字符串或字符串,不能在它被使用NSString类对象创建的改变。
1.Symbols
1.1 Creating and Initializing a Mutable String
1.2 Modifying a String
- - appendFormat:
- - appendString:
- - applyTransform:reverse:range:updatedRange:
- - deleteCharactersInRange:
- - insertString:atIndex:
- - replaceCharactersInRange:withString:
- - replaceOccurrencesOfString:withString:options:range:
- - setString:
1.3 Constants
2. Relationships
2.1 Inherits From NSString
来源:oschina
链接:https://my.oschina.net/u/2721020/blog/674154