String

class String

A string is a series of characters, such as "Hey mom, there's something in the backroom hope it's not the creatures from above." or "You used to read me stories as if my dreams were boring.".

  • The number of characters in the string.

    Declaration

    var count: Double { get }
  • The number of lines in the string.

    Declaration

    var lineCount: Double { get }
  • The object’s description

    Declaration

    var description: String { get }
  • Compares two values for equality.

    The equals function is invoked using infix notation as in the following code snippet: lhs == rhs.

    Declaration

    func equals(_ lhs: String) -> Bool

    Parameters

    lhs

    A value.

    rhs

    Another value.

    Return Value

    true if the lhs and rhs are equal, false otherwise.

  • Replaces all uppercase characters by their lowercase counterparts.

    Declaration

    func lowercased() -> String

    Return Value

    A lowercased version of the original string.

  • Replaces all lowercase characters by their uppercase counterparts.

    Declaration

    func uppercased() -> String

    Return Value

    An uppercased version of the original string.

  • Removes whitespaces from the start and end.

    Declaration

    func trimmingWhitespace() -> String

    Return Value

    A trimmed version of the original string.

  • Removes all whitespaces from the string.

    Declaration

    func removingWhitespaces() -> String

    Return Value

    A new string stripped of all newlines and white spaces.

  • Declaration

    func escaped() -> String

    Return Value

    An escaped version of the original string.

  • Converts the string to lowerCamelCase.

    Declaration

    func lowerCamelCased() -> String

    Return Value

    A lowerCamelCased version of the original string.

  • Converts the string to UpperCamelCase.

    Declaration

    func upperCamelCased() -> String

    Return Value

    An upperCamelCased version of the original string.

  • Converts the string to snake_case.

    Declaration

    func snakeCased() -> String

    Return Value

    A snakeCased version of the original string.

  • Determines whether the string starts with the specified prefix.

    Declaration

    func hasPrefix(_ prefix: String) -> Bool

    Parameters

    prefix

    A string.

    Return Value

    true if the string begins with prefix, false otherwise.

  • Determines whether the string ends with the specified suffix.

    Declaration

    func hasSuffix(_ suffix: String) -> Bool

    Parameters

    suffix

    A string.

    Return Value

    true if the string ends with suffix, false otherwise.

  • Determines whether the string contains the specified substring.

    Declaration

    func contains(_ subString: String) -> Bool

    Parameters

    subString

    A string.

    Return Value

    true if the string contains any occurences of subString, false otherwise.

  • Appends a suffix to the string.

    Declaration

    func appending(_ suffix: String) -> String

    Parameters

    suffix

    A string.

    Return Value

    The original string with suffix appened to it.

  • Seperates the string into components using the specified seperator. For example, “1,2,3”.components(separatedBy: “,”) yields [“1”, “2”, “3”]

    Declaration

    func components(separatedBy seperator: String) -> Array

    Parameters

    seperator

    The seperator used seperate the string into components.

    Return Value

    An array of strings containing the components of the original string.

  • Replaces all occurences of subString with replacement.

    Declaration

    func replacingOccurrences(of subString: String, with replacement: String) -> String

    Parameters

    subString

    The string to search for.

    replacement

    The string used to replace subString.

    Return Value

    Returns a new string in which all occurrences of subString are replaced by replacement.

  • Surrounds the string with quotation marks.

    Declaration

    func inQuotes() -> String

    Return Value

    Returns a new string formed by surrounding the original string with quotation marks.