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

##Editing

capitalized

  • capitalized () -> String

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

Example

"ciao".capitalized()
// → Ciao

ltrimmed

  • ltrimmed () -> String

Strip whitespace from the beginning of a string.

Example

" \nCiao".ltrimmed()
// → Ciao

rtrimmed

  • rtrimmed () -> String

Strip whitespace from the end of a string.

Example

"Ciao \n".rtrimmed()
// → Ciao

trimmed

  • trimmed () -> String

Strip whitespace from the beginning and end of a string.

Example

" \nCiao \n".trimmed()
// → Ciao

insert

  • insert (index: Int, _ string: String) -> String

Inserts string before the character at the given index.

Example

"Heo".insert(2, "ll")
// → Hello

##Misc

#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 ##Subscript ##Star ##Matching

Clone this wiki locally