String
struct String
-
Converts a plain ol’ integer index into a
String.IndexType
.Declaration
Swift
public func index(_ i: Int) -> IndexType
Parameters
i
a zero-based character index into this string.
returns
Return Value
a String.IndexType for the same character position.
-
Inserts a new element at a given index in this string.
Declaration
Swift
public mutating func insert(_ newElement: Character, at i: Int)
Parameters
newElement
the character to be added
i
an index into the string 0 <= i <= self.count
-
Inserts the contents of sequence at a given index in this string.
Declaration
Swift
public mutating func insert<S>(contentsOf: S, at i: Int) where S:Collection, S.Iterator.Element == Character
Parameters
newElement
the character to be added
i
an index into the string 0 <= i <= self.count
-
Replaces a range of characters in this string with a given sequence.
Declaration
Swift
public mutating func replaceSubrange<C>(_ subrange: CountableRange<Int>, with newElements:C) where C : Collection, Character == C.Iterator.Element
Parameters
subrange
the range of characters to be replaced
newElements
the replacement sequence
-
Replaces a closed range of characters in this string with a given sequence.
Declaration
Swift
public mutating func replaceSubrange<C>(_ subrange: CountableClosedRange<Int>, with newElements:C) where C : Collection, Character == C.Iterator.Element
Parameters
subrange
the range of characters to be replaced
newElements
the replacement sequence
-
Removes a character at a given index and returns the character
- at: the index of the character to be removed
Declaration
Swift
@discardableResult public mutating func remove(at: Int) -> Character
Return Value
the removed character
-
Removes a closed range of characters from this string
- subrange: the index of the character to be removed
Declaration
Swift
public mutating func removeSubrange(_ subrange: CountableClosedRange<Int>)
-
Removes a range of characters from this string
- subrange: the index of the character to be removed
Declaration
Swift
public mutating func removeSubrange(_ subrange: CountableRange<Int>)
-
The number of characters in this string.
Declaration
Swift
public var count: Int
-
Removes and returns the first character of this string.
Declaration
Swift
@discardableResult public mutating func removeFirst() -> Character
Return Value
the removed character.
-
Removes a number of characters from the beginning of this string.
Declaration
Swift
public mutating func removeFirst(_ n: Int)
Parameters
n
the number of characters to remove
-
Removes a number of characters from the end of this string.
Declaration
Swift
public mutating func removeLast(_ n: Int)
Parameters
n
the number of characters to remove
-
Removes the last character from this string.
Declaration
Swift
@discardableResult public mutating func removeLast() -> Character
Return Value
the removed character
-
Returns the string obtained by removing the first character of this string
Declaration
Swift
public func dropFirst() -> SubstringType
Return Value
the substring of characters after the first character.
-
Returns the string obtained by removing the first
n
characters of this string.Declaration
Swift
public func dropFirst(_ n: Int) -> SubstringType
Parameters
n
the number of characters to remove.
-
Returns the string obtained by removing the last character of this string
Declaration
Swift
public func dropLast() -> SubstringType
Return Value
the substring of characters containing all but the last.
-
Returns the string obtained by removing the last
n
characters of this string.Declaration
Swift
public func dropLast(_ n: Int) -> SubstringType
Parameters
n
the number of characters to remove.