Strings and Characters
suggest changeSyntax
- String.characters // Swift 3 character view. Swift 4 and later iterate the String itself. Not an Array.
- String.characters.count // The number of extended grapheme clusters
- String.utf8 // A String.UTF8View, the UTF-8 code units
- String.utf16 // A String.UTF16View, the UTF-16 code units
- String.unicodeScalars // A String.UnicodeScalarView, the Unicode scalars
- String.isEmpty // Returns true if the String does not contain any text
- String.hasPrefix(String) // Returns true if the String is prefixed with the argument
- String.hasSuffix(String) // Returns true if the String is suffixed with the argument
- String.startIndex // Returns the Index that corresponds to the first character in the string
- String.endIndex // Returns the Index that corresponds to the spot after the last character in the string
- String.components(separatedBy: String) // Returns an array containing the substrings separated by the given separator string
- String.append(Character) // Adds the character (given as argument) to the String
Remarks
A String is a collection of characters (extended grapheme clusters). A character can contain more than one Unicode scalar. Strings can hold any Unicode text, including languages other than English and emoji.
Because two scalars could combine to form a single character, the number of scalars in a String is not necessarily always the same as the number of characters.
For more information about Strings, see The Swift Programming Language and the String Structure Reference.
For implementation details, see “Swift String Design”
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents