String

public extension String
  • Returns the base64 encoded version, i.e. "FooBar".base64Encoded == "Rm9vQmFy"

    Declaration

    Swift

    var base64Encoded: String? { get }
  • Returns the base64 decoded version, i.e. "Rm9vQmFy".base64Decoded == "FooBar"

    Declaration

    Swift

    var base64Decoded: String? { get }
  • Represents the empty string "".

    Declaration

    Swift

    static let empty: String
  • Represents the new line string \n.

    Declaration

    Swift

    static let newLine: String
  • Crops the string to a given number of characters, truncating the rest and replacing the last 3 characters with ‘…’.

    Returns the unmodified string if it has equal or less characters.

    When cropping would result in less than 3 characters then the three dot’s will be skipped and only the cropped text will be returned.

    Declaration

    Swift

    func truncated(numberOfCharacters: Int) -> String

    Parameters

    numberOfCharacters

    The maximum length the string should have. Negative values are ignored.

    Return Value

    The truncated string.

  • Returns this string with the first character capitalized, leaving the rest unchanged.

    When the first character is replaced by multiple characters when uppercased then only the first replacing character gets uppercased.

    Examples:

    • “dž” -> “Dž”
    • “ß” -> “Ss”
    • “œ” -> “Œ”

    Usually this is the desired behavior when capitalizing a string rather than firstUppercased.

    Declaration

    Swift

    var firstCapitalized: String { get }
  • Returns the string with the first character uppercased, leaving the rest unchanged.

    When the first character is replaced by multiple characters when uppercased then all replacing characters get uppercased.

    Examples:

    • “dž” -> “DŽ”
    • “ß” -> “SS”
    • “œ” -> “Œ”

    Usually firstCapitalized is the desired behavior.

    Declaration

    Swift

    var firstUppercased: String { get }