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
equalsfunction is invoked using infix notation as in the following code snippet:lhs == rhs.Declaration
func equals(_ lhs: String) -> BoolParameters
lhsA value.
rhsAnother value.
Return Value
trueif thelhsandrhsare equal,falseotherwise. -
Replaces all uppercase characters by their lowercase counterparts.
Declaration
func lowercased() -> StringReturn Value
A lowercased version of the original string.
-
Replaces all lowercase characters by their uppercase counterparts.
Declaration
func uppercased() -> StringReturn Value
An uppercased version of the original string.
-
Removes whitespaces from the start and end.
Declaration
func trimmingWhitespace() -> StringReturn Value
A trimmed version of the original string.
-
Removes all whitespaces from the string.
Declaration
func removingWhitespaces() -> StringReturn Value
A new string stripped of all newlines and white spaces.
-
Declaration
func escaped() -> StringReturn Value
An escaped version of the original string.
-
Converts the string to lowerCamelCase.
Declaration
func lowerCamelCased() -> StringReturn Value
A lowerCamelCased version of the original string.
-
Converts the string to UpperCamelCase.
Declaration
func upperCamelCased() -> StringReturn Value
An upperCamelCased version of the original string.
-
Converts the string to snake_case.
Declaration
func snakeCased() -> StringReturn Value
A snakeCased version of the original string.
-
Determines whether the string starts with the specified prefix.
Declaration
func hasPrefix(_ prefix: String) -> BoolParameters
prefixA string.
Return Value
trueif the string begins withprefix,falseotherwise. -
Determines whether the string ends with the specified suffix.
Declaration
func hasSuffix(_ suffix: String) -> BoolParameters
suffixA string.
Return Value
trueif the string ends withsuffix,falseotherwise. -
Determines whether the string contains the specified substring.
Declaration
func contains(_ subString: String) -> BoolParameters
subStringA string.
Return Value
trueif the string contains any occurences ofsubString,falseotherwise. -
Appends a suffix to the string.
Declaration
func appending(_ suffix: String) -> StringParameters
suffixA string.
Return Value
The original string with
suffixappened 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) -> ArrayParameters
seperatorThe seperator used seperate the string into components.
Return Value
An array of strings containing the components of the original string.
-
Replaces all occurences of
subStringwithreplacement.Declaration
func replacingOccurrences(of subString: String, with replacement: String) -> StringParameters
subStringThe string to search for.
replacementThe string used to replace
subString.Return Value
Returns a new string in which all occurrences of
subStringare replaced byreplacement. -
Surrounds the string with quotation marks.
Declaration
func inQuotes() -> StringReturn Value
Returns a new string formed by surrounding the original string with quotation marks.