This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 315
String
pNre edited this page Jun 14, 2014
·
20 revisions
-
Properties
-
Instance methods
-
Class methods
-
Operators
#Properties
Length of
self
.
"Hello".length
// → 5
#Instance methods ##Sub-strings
at (indexes: Int...) -> String[]
Returns an array of characters at
indexes
inself
.
let str = "This is a string"
str.at(2, 3, 5)
// → ["i", "s", "i"]
##Pattern matching
matches (pattern: String, ignoreCase: Bool = false) -> NSTextCheckingResult[]?
Creates an
NSRegularExpression
object withpattern
and 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)]
// → 31
capitalized () -> String
self
with the first character changed to its corresponding uppercase value.
"ciao".capitalized()
// → Ciao
#Class methods
func random (var length len: Int = 0, charset: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") -> String
Returns a string of length
len
using random characters fromcharset
.
String.random(6)
// → fi30Xw
#Operators