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
lhsA value.
rhsAnother value.
Return Value
true
if thelhs
andrhs
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
prefixA string.
Return Value
true
if the string begins withprefix
,false
otherwise. -
Determines whether the string ends with the specified suffix.
Declaration
func hasSuffix(_ suffix: String) -> Bool
Parameters
suffixA string.
Return Value
true
if the string ends withsuffix
,false
otherwise. -
Determines whether the string contains the specified substring.
Declaration
func contains(_ subString: String) -> Bool
Parameters
subStringA string.
Return Value
true
if the string contains any occurences ofsubString
,false
otherwise. -
Appends a suffix to the string.
Declaration
func appending(_ suffix: String) -> String
Parameters
suffixA 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
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
subString
withreplacement
.Declaration
func replacingOccurrences(of subString: String, with replacement: String) -> String
Parameters
subStringThe string to search for.
replacementThe string used to replace
subString
.Return Value
Returns a new string in which all occurrences of
subString
are replaced byreplacement
. -
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.