Instance Methodswift 6.0.1Swift

    remove(at:)

    Removes and returns the character at the specified position.

    @discardableResult mutating func remove(at i: String.Index) -> Character

    Parameters

    i

    The position of the character to remove. i must be a valid index of the string that is not equal to the string’s end index.

    Returns

    The character that was removed.

    All the elements following i are moved to close the gap. This example removes the hyphen from the middle of a string.

    var nonempty = "non-empty"
    if let i = nonempty.firstIndex(of: "-") {
        nonempty.remove(at: i)
    }
    print(nonempty)
    // Prints "nonempty"

    Calling this method invalidates any existing indices for use with this string.

    Other members in extension

    Types

    Typealiases

    Show obsolete interfaces (2)

    Hide obsolete interfaces

    Type members

    Show obsolete interfaces (17)

    Hide obsolete interfaces

    Instance members

    Show obsolete interfaces (3)

    Hide obsolete interfaces