Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
pNre edited this page Jun 14, 2014 · 20 revisions

Contents

#Properties

length

Length of self.

Example

"Hello".length
// → 5

#Instance methods ##Sub-strings

at

  • at (indexes: Int...) -> String[]

Returns an array of characters at indexes in self.

Example

let str = "This is a string"
str.at(2, 3, 5)
// → ["i", "s", "i"]

##Pattern matching

matches

  • matches (pattern: String, ignoreCase: Bool = false) -> NSTextCheckingResult[]?

Creates an NSRegularExpression object with pattern and returns all the matches in self.

Example

let string = "AB[31]"
let matches = string.matches("\\d+")!
let range = matches[0].rangeAtIndex(0)

string[range.location..(range.location + range.length)]
// → 31

capitalized

  • capitalized () -> String

self with the first character changed to its corresponding uppercase value.

Example

"ciao".capitalized()
// → Ciao

#Class methods

random

  • func random (var length len: Int = 0, charset: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") -> String

Returns a string of length len using random characters from charset.

Example

String.random(6)
// → fi30Xw

#Operators

Clone this wiki locally