| Start |
|---|
Encoding and Decoding Some supported encodings are:
Note that |
| String Length NSString has a As in the Splitting Example (opens new window), keep in mind that Here are some cases that might be surprising: In order to get the number of user-perceived characters, known technically as "grapheme clusters (opens new window)", you must iterate over the string with |
| Comparing Strings Strings are compared for equality using The The expression If the string variables can be This condition returns To order two strings alphabetically, use
To compare two strings equality, use To compare with the empty string ( |
| Splitting You can split a string into an array of parts, divided by a separator character. If you need to split on a set of several different delimiters, use If you need to break a string into its individual characters, loop over the length of the string and convert each character into a new string. As in the Length Example (opens new window), keep in mind that a "character" here is a UTF-16 code unit, not necessarily what the user sees as a character. If you use this loop with In order to get a list of the user-perceived characters, use This preserves grapheme clusters (opens new window) like the Italian flag as a single substring. |
| Creation Simple: From multiple strings: Using Mutable String From NSData: When initializing from Avoid using From NSArray: |
| Searching for a Substring To search if a String contains a substring, do the following: If targeting iOS 7 or OS X 10.9 (or earlier): |
| Changing Case To convert a String to uppercase, use To convert a String to lowercase, use To capitalize the first letter character of each word in a string, use |
| Joining an Array of Strings To combine an |
Removing Leading and Trailing Whitespace Method stringByTrimmingCharactersInSet returns a new string made by removing from both ends of the String characters contained in a given character set. We can also just remove only whitespace or newline |
| Formatting The It is possible to format integers Or any object subclassed from NSObject For a complete list of Format Specifiers, please see: Objective-C, Format Specifiers, Syntax (opens new window) |
| Working with C Strings To convert You could also use For the reverse path use Once you have the If you want to modify the string, make a copy: |
Reversing a NSString Objective-C RemarksFor nesting various types of objects and data-types into NSStrings refer to: Objective-C, Format Specifiers (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference