Ojbect-C2 2、NSString和NSMutableString字符串的使用

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 OS X v10.4
  • + stringWithCString:length: Deprecated in OS X v10.4
  • – initWithCString: Deprecated in OS X v10.4
  • – initWithCString:length: Deprecated in OS X v10.4
  • – initWithCStringNoCopy:length:freeWhenDone: Deprecated in OS X v10.4

Creating and Initializing a String from a File

  • + stringWithContentsOfFile:encoding:error:
  • – initWithContentsOfFile:encoding:error:
  • + stringWithContentsOfFile:usedEncoding:error:
  • – initWithContentsOfFile:usedEncoding:error:
  • + stringWithContentsOfFile: Deprecated in OS X v10.4
  • – initWithContentsOfFile: Deprecated in OS X v10.4

Creating and Initializing a String from an URL

  • + stringWithContentsOfURL:encoding:error:
  • – initWithContentsOfURL:encoding:error:
  • + stringWithContentsOfURL:usedEncoding:error:
  • – initWithContentsOfURL:usedEncoding:error:
  • + stringWithContentsOfURL: Deprecated in OS X v10.4
  • – initWithContentsOfURL: Deprecated in OS X v10.4

Writing to a File or URL

  • – writeToFile:atomically:encoding:error:
  • – writeToURL:atomically:encoding:error:
  • – writeToFile:atomically: Deprecated in OS X v10.4
  • – writeToURL:atomically: Deprecated in OS X v10.4

Getting a String’s Length

  • – length
  • – lengthOfBytesUsingEncoding:
  • – maximumLengthOfBytesUsingEncoding:

Getting Characters and Bytes

  • – characterAtIndex:
  • – getCharacters:range:
  • – getBytes:maxLength:usedLength:encoding:options:range:remainingRange:
  • – getCharacters: Deprecated in OS X v10.6

Getting C Strings

  • – cStringUsingEncoding:
  • – getCString:maxLength:encoding:
  • – UTF8String
  • – cString Deprecated in OS X v10.4
  • – cStringLength Deprecated in OS X v10.4
  • – getCString: Deprecated in OS X v10.4
  • – getCString:maxLength: Deprecated in OS X v10.4
  • – getCString:maxLength:range:remainingRange: Deprecated in OS X v10.4
  • – lossyCString Deprecated in OS X v10.4

Combining Strings   --字符串拼接

  • – stringByAppendingFormat:
  • – stringByAppendingString:
  • – stringByPaddingToLength:withString:startingAtIndex:

Dividing Strings    --字符串分割

  • – componentsSeparatedByString:       --字符串转换成数组
  • – componentsSeparatedByCharactersInSet:
  • – stringByTrimmingCharactersInSet:
  • – substringFromIndex:      --从。。。截取字符串
  • – substringWithRange:    --从。。。开始截取多长的字符串
  • – substringToIndex: --截取到。。。字符串

Finding Characters and Substrings   --查找字符串

  • – rangeOfCharacterFromSet:
  • – rangeOfCharacterFromSet:options:
  • – rangeOfCharacterFromSet:options:range:
  • – rangeOfString:   --查找字符串
  • – rangeOfString:options:
  • – rangeOfString:options:range:
  • – rangeOfString:options:range:locale:
  • – enumerateLinesUsingBlock:
  • – enumerateSubstringsInRange:options:usingBlock:

Replacing Substrings

  • – stringByReplacingOccurrencesOfString:withString:
  • – stringByReplacingOccurrencesOfString:withString:options:range:
  • – stringByReplacingCharactersInRange:withString:

Determining Line and Paragraph Ranges

  • – getLineStart:end:contentsEnd:forRange:
  • – lineRangeForRange:
  • – getParagraphStart:end:contentsEnd:forRange:
  • – paragraphRangeForRange:

Determining Composed Character Sequences

  • – rangeOfComposedCharacterSequenceAtIndex:
  • – rangeOfComposedCharacterSequencesForRange:

Converting String Contents Into a Property List

  • – propertyList
  • – propertyListFromStringsFileFormat

Identifying and Comparing Strings

  • – caseInsensitiveCompare:        比较字符串大小
  • – localizedCaseInsensitiveCompare:
  • – compare:
  • – localizedCompare:
  • – compare:options:
  • – compare:options:range:
  • – compare:options:range:locale:
  • – localizedStandardCompare:
  • – hasPrefix:
  • – hasSuffix:
  • – isEqualToString:          比较字符串内容
  • – hash

Folding Strings

  • – stringByFoldingWithOptions:locale:

Getting a Shared Prefix

  • – commonPrefixWithString:options:

Changing Case     

  • – capitalizedString
  • – capitalizedStringWithLocale:
  • – lowercaseString                     全部小写
  • – lowercaseStringWithLocale:
  • – uppercaseString                     全部大写
  • – uppercaseStringWithLocale:

Getting Strings with Mapping

  • – decomposedStringWithCanonicalMapping
  • – decomposedStringWithCompatibilityMapping
  • – precomposedStringWithCanonicalMapping
  • – precomposedStringWithCompatibilityMapping

Getting Numeric Values

  • – doubleValue
  • – floatValue
  • – intValue
  • – integerValue
  • – longLongValue
  • – boolValue

Working with Encodings

  • + availableStringEncodings
  • + defaultCStringEncoding
  • + localizedNameOfStringEncoding:
  • – canBeConvertedToEncoding:
  • – dataUsingEncoding:
  • – dataUsingEncoding:allowLossyConversion:
  • – description
  • – fastestEncoding
  • – smallestEncoding

Working with Paths

  • + pathWithComponents:
  • – pathComponents
  • – completePathIntoString:caseSensitive:matchesIntoArray:filterTypes:
  • – fileSystemRepresentation
  • – getFileSystemRepresentation:maxLength:
  • – isAbsolutePath
  • – lastPathComponent
  • – pathExtension
  • – stringByAbbreviatingWithTildeInPath
  • – stringByAppendingPathComponent:
  • – stringByAppendingPathExtension:
  • – stringByDeletingLastPathComponent
  • – stringByDeletingPathExtension
  • – stringByExpandingTildeInPath
  • – stringByResolvingSymlinksInPath
  • – stringByStandardizingPath
  • – stringsByAppendingPaths:

Working with URLs

  • – stringByAddingPercentEscapesUsingEncoding:
  • – stringByReplacingPercentEscapesUsingEncoding:
  • – stringByAddingPercentEncodingWithAllowedCharacters:
  • – stringByRemovingPercentEncoding

Linguistic Tagging and Analysis

  • – enumerateLinguisticTagsInRange:scheme:options:orthography:usingBlock:
  • – linguisticTagsInRange:scheme:options:orthography:tokenRanges:






NSMutableString 


Creating and Initializing a Mutable String

  • + stringWithCapacity:
  • – initWithCapacity:

Modifying a String

  • – appendFormat:
  • – appendString:
  • – deleteCharactersInRange:
  • – insertString:atIndex:
  • – replaceCharactersInRange:withString:
  • – replaceOccurrencesOfString:withString:options:range:
  • – setString:

你可能感兴趣的:(Ojbect-C2 2、NSString和NSMutableString字符串的使用)