Objective-C ---NSString(梳理整理)

限于喜欢 提交于 2020-04-06 20:21:16

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:

  1. length:The number of UTF-16 code units in the receiver.
  2. - lengthOfBytesUsingEncoding: Returns the number of bytes required to store the receiver in a given encoding.返回在给定编码中存储接收器所需的字节数。
  3. - 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:(组合字符串)

  1. -stringByAppendingFormat:
  2. -stringByAppendingString:
  3. - stringByPaddingToLength:withString:startingAtIndex:

1.10 Dividing Strings:(分割字符串)

  1. - componentsSeparatedByString:
  2. - componentsSeparatedByCharactersInSet:
  3. - stringByTrimmingCharactersInSet:
  4. - substringFromIndex:
  5. - substringWithRange:
  6. - substringToIndex:

1.11 Finding Characters and Substrings(查找字符和子串)

  1. - containsString :
  2. -localizedCaseInsensitiveContainsString:
  3. -localizedStandardContainsString:
  4. -rangeOfCharacterFromSet:
  5. -rangeOfCharacterFromSet:options:
  6. -rangeOfCharacterFromSet:options:range: 
  7. -rangeOfString:
  8. - rangeOfString:options:
  9. -rangeOfString:options:range:
  10. -rangeOfString:options:range:locale: 
  11. -localizedStandardRangeOfString: 
  12. -enumerateLinesUsingBlock: 
  13. -enumerateSubstringsInRange:options:usingBlock: 

1.12 Replacing Substrings(替换子字符串)

  1. - stringByReplacingOccurrencesOfString:withString:
  2. - stringByReplacingOccurrencesOfString:withString:options:range:
  3. - 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

  1. - appendFormat:
  2. - appendString:
  3. - applyTransform:reverse:range:updatedRange:
  4. - deleteCharactersInRange:
  5. - insertString:atIndex:
  6. - replaceCharactersInRange:withString:
  7. - replaceOccurrencesOfString:withString:options:range:
  8. - setString:

1.3 Constants

2. Relationships

2.1 Inherits From NSString

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!