-
Notifications
You must be signed in to change notification settings - Fork 314
String
- Properties
- Instance methods
- Class methods
- Operators
Length of
self.
"Hello".length
// → 5at (indexes: Int...) -> String[]
Returns an array of characters at
indexesinself.
let str = "This is a string"
str.at(2, 3, 5)
// → ["i", "s", "i"]matches (pattern: String, ignoreCase: Bool = false) -> NSTextCheckingResult[]?
Creates an
NSRegularExpressionobject withpatternand returns all the matches inself.
let string = "AB[31]"
let matches = string.matches("\\d+")!
let range = matches[0].rangeAtIndex(0)
string[range.location...(range.location + range.length)]
// → 31capitalized () -> String
selfwith the first character changed to its corresponding uppercase value.
"ciao".capitalized()
// → Ciaoltrimmed () -> String
Strip whitespace from the beginning of a string.
" \nCiao".ltrimmed()
// → Ciaortrimmed () -> String
Strip whitespace from the end of a string.
"Ciao \n".rtrimmed()
// → Ciaotrimmed () -> String
Strip whitespace from the beginning and end of a string.
" \nCiao \n".trimmed()
// → Ciaoinsert (index: Int, _ string: String) -> String
Inserts
stringbefore the character at the givenindex.
"Heo".insert(2, "ll")
// → Helloexplode (separator: Character) -> String[]
Returns an array of strings, each of which is a substring of
selfformed by splitting it onseparator.
"Hello World".explode(" ")
// → ["Hello", "World"]random (var length len: Int = 0, charset: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") -> String
Returns a string of length
lenusing random characters fromcharset.
String.random(6)
// → fi30Xwsubscript (range: Range<Int>) -> String?
Returns a substring of
selfin the givenrange.
subscript (indexes: Int...) -> String[]
Equivalent to
at.
subscript (index: Int) -> String?
Returns the char at position
indexinself.
* (first: String, n: Int) -> String
Returns a new string by repeating
first,ntimes.
"Ab" * 3
// → AbAbAb=~ (string: String, pattern: String) -> Bool=~ (string: String, options: (pattern: String, ignoreCase: Bool)) -> Bool
Returns
trueifstringmatchespattern. Ifoptions.ignoreCaseis specified and isfalsethe matching is done case-sensitively.
=~ (strings: String[], pattern: String) -> Bool=~ (strings: String[], options: (pattern: String, ignoreCase: Bool)) -> Bool
Returns
trueif all the strings instringsmatchpattern.
|~ (strings: String[], pattern: String) -> Bool|~ (strings: String[], options: (pattern: String, ignoreCase: Bool)) -> Bool
Returns
trueif any string instringsmatchespattern.