String

struct String
  • A Boolean value indicating if all the characters are letters.

    Declaration

    Swift

    func isAlpha() -> Bool

    Return Value

    True, if all characters are letters. Otherwise, false.

  • A Boolean value indicating if all the characters are alphanumeric.

    Declaration

    Swift

    func isAlphanumeric() -> Bool

    Return Value

    True, if all characters are alphanumeric. Otherwise, false.

  • A Boolean value indicating if the string is capitalized.

    Declaration

    Swift

    func isCapitalized() -> Bool

    Return Value

    True, if the string is capitalized. Otherwise, false.

  • A Boolean value indicating if the string’s first character is lowercase.

    Declaration

    Swift

    func isDecapitalized() -> Bool

    Return Value

    True, if first character is lowercased. Otherwise, false.

  • A Boolean value indicating if all the characters are lowercased.

    Declaration

    Swift

    func isLowercased() -> Bool

    Return Value

    True, if the string is not capitalized. Otherwise, false.

  • A Boolean value indicating if all the characters are numbers.

    Declaration

    Swift

    func isNumeric() -> Bool

    Return Value

    True, if all characters are numbers. Otherwise, false.

  • A Boolean value indicating if all the characters are uppercased.

    Declaration

    Swift

    func isUppercased() -> Bool

    Return Value

    True, if all characters are uppercased. Otherwise, false.

  • Returns a camel cased version of the string.

    Example:

    let string = "HelloWorld"
    print(string.decapitalized())
    // Prints "helloWorld"
    

    Declaration

    Swift

    func camelCased() -> String

    Return Value

    A camel cased copy of the string.

  • Returns a decapitalized version of the string.

    Example:

    let string = "HELLOWORLD"
    print(string.decapitalized())
    // Prints "helloworld"
    

    Declaration

    Swift

    func decapitalized() -> String

    Return Value

    A decapitalized copy of the string.

  • Returns the kebab cased version of the string.

    Example:

    let string = "Hello World"
    print(string.kebabCased())
    // Prints "-Hellow-World-"
    

    Declaration

    Swift

    func kebabCased() -> String

    Return Value

    The kebab cased copy of the string.

  • Returns a pascal cased version of the string.

    Example:

    let string = "HELLO WORLD"
    print(string.pascalCased())
    // Prints "HelloWorld"
    

    Declaration

    Swift

    func pascalCased() -> String

    Return Value

    A pascal cased copy of the string.

  • Returns the slug version of the string.

    Example:

    let string = "Hello World"
    print(string.slugCased())
    // Prints "Hello-World"
    

    Declaration

    Swift

    func slugCased() -> String

    Return Value

    The slug copy of the string.

  • Returns the snake cased version of the string.

    Example:

    let string = "hello world"
    print(string.snakeCased())
    // Prints "hello_world"
    

    Declaration

    Swift

    func snakeCased() -> String

    Return Value

    The slug copy of the string.

  • Returns the swap cased version of the string.

    Example:

    let string = "Hello World"
    print(string.swapCased())
    // Prints "hELLO wORLD"
    

    Declaration

    Swift

    func swapCased() -> String

    Return Value

    The swap cased copy of the string.

  • Returns the first character of the string.

    Example:

    let string = "Hello World"
    print(string.first())
    // Prints "H"
    

    Declaration

    Swift

    func first() -> String

    Return Value

    The first character of the string.

  • Returns the laster character of the string.

    Example:

    let string = "Hello World"
    print(string.last())
    // Prints "d"
    

    Declaration

    Swift

    func last() -> String

    Return Value

    The last character of the string.

  • Returns the character count of the string.

    Declaration

    Swift

    func length() -> Int

    Return Value

    The character count of the string.

  • Retuns the reversed version of the string.

    Example:

    let string = "Hello World"
    print(string.reversedreversed())
    // Prints "dlroW olleH"
    

    Declaration

    Swift

    func reversed() -> String

    Return Value

    The reversed copy of the string.

  • Returns the center-padded version of the string.

    Example 1:

    let string = "Hello World"
    print(string.pad(length: 13))
    // Prints " Hello World "
    

    Example 2:

    let string = "Hello World"
    print(string.pad(length: 13, withToken: "*"))
    // Prints "*Hello World*"
    

    Declaration

    Swift

    func pad(length: Int, withToken token: String = " ") -> String

    Parameters

    length

    The final length of your string. If the provided length is less than or equal to the original string, the original string is returned. If the the sum-total of characters added is odd, the left side of the string will have one less instance of the token.

    token

    The string used to pad the String. Must be 1 character in length. Defaults to a white space if the parameter is left blank.

    Return Value

    The padded copy of the string.

  • Returns the left-padded version of the string.

    Example 1:

    let string = "Hello World"
    print(string.padLeft(length: 13))
    // Prints "Hello World  "
    

    Example 2:

    let string = "Hello World"
    print(string.padLeft(length: 13, withToken: "*"))
    // Prints "Hello World**"
    

    Declaration

    Swift

    func padLeft(length: Int, withToken token: String = " ") -> String

    Parameters

    length

    The final length of your string. If the provided length is less than or equal to the original string, the original string is returned.

    token

    The string used to pad the String. Must be 1 character in length. Defaults to a white space if the parameter is left blank.

    Return Value

    The left-padded copy of the string.

  • Returns the right-padded version of the string.

    Example 1:

    let string = "Hello World"
    print(string.padRight(length: 13))
    // Prints "  Hello World"
    

    Example 2:

    let string = "Hello World"
    print(string.padRight(length: 13, withToken: "*", ))
    // Prints "  Hello World"
    

    Declaration

    Swift

    func padRight(length: Int, withToken token: String = " ") -> String

    Parameters

    length

    The final length of your string. If the provided length is less than or equal to the original string, the original string is returned.

    token

    The string used to pad the String. Must be 1 character in length. Defaults to a white space if the parameter is left blank.

    Return Value

    The right-padded copy of the string.

  • Returns a prefixed version of the string.

    Example:

    let string = "Hello World"
    print(string.prefixed(length: 7))
    // Prints "Hello W"
    

    Declaration

    Swift

    func prefixed(length: Int) -> String

    Parameters

    length

    The length of the string that you’d like to return, starting at the beginning of the string. If the provided length is greater than the original string, the original string is returned.

    Return Value

    A prefixed copy of the string.

  • Returns a suffixed version of the string.

    Example:

    let string = "Hello World"
    print(string.prefixed(length: 7))
    // Prints "o World"
    

    Declaration

    Swift

    func suffixed(length: Int) -> String

    Parameters

    length

    The length of the string that you’d like to return, starting at the end of the string. If the provided length is greater than the original string, the original string is returned.

    Return Value

    A prefixed copy of the string.

  • Returns the left-trimmed version of the string.

    Example:

    let string = "Hello World"
    print(string.trimLeft(length: 7))
    // Prints "o World"
    

    Declaration

    Swift

    func trimLeft(length: Int) -> String

    Parameters

    length

    The number of characters to trim from the beginning of the string. If the provided length is greater than the original string, the original string is returned.

    Return Value

    The left-trimmed copy of the string.

  • Returns the right-trimmed version of the string.

    Example 1:

    let string = "Hello World"
    print(string.trimRight(length: 7))
    // Prints "Hello W"
    

    Declaration

    Swift

    func trimRight(length: Int) -> String

    Parameters

    length

    The number of characters to trim from the end of the string. If the provided length is greater than the original string, the original string is returned.

    Return Value

    The right-trimmed copy of the string.

  • Returns the truncated string with an ellipsis.

    Example:

    let string = "Hello World"
    print(string.truncate(length: 8))
    // Prints "Hello..."
    

    Declaration

    Swift

    func truncate(length: Int) -> String

    Parameters

    length

    The final length of the string, which includes the ellipsis: ...).

    Return Value

    The truncated copy of the string.