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 first characters in all of the words in the string are uppercased.
Declaration
Swift
func isCapitalized() -> Bool
Return Value
true
, if the string is capitalized. Otherwise,false
. -
A Boolean value indicating if the first characters in all of the words in the string are lowercased.
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.
let string = "HelloWorld" print(string.camelCased()) // Prints "helloWorld"
Declaration
Swift
func camelCased() -> String
Return Value
A camel cased copy of the string.
-
Returns a capitalized version of the string.
Warning
This method is a modified implementation of Swift stdlib’s
capitalized
computer variabled.let string =
hello World
print(string.capitalized()) // PrintsHello World
Declaration
Swift
func capitalized() -> String
Return Value
A capitalized copy of the string.
-
Returns a decapitalized version of the string.
let string = "Hello World" print(string.decapitalized()) // Prints "hello world"
Declaration
Swift
func decapitalized() -> String
Return Value
A decapitalized copy of the string.
-
Returns the kebab cased (a.k.a. slug) version of the string.
let string = "Hello World" print(string.kebabCased()) // Prints "hello-world"
Declaration
Swift
func kebabCased() -> String
Return Value
The kebabg cased copy of the string.
-
Returns a pascal cased version of the string.
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 snake cased version of the string.
let string = "Hello World" print(string.snakeCased()) // Prints "hello_world"
Declaration
Swift
func snakeCased() -> String
Return Value
The snaked cased copy of the string.
-
Splits a string into mutliple words, delimited by uppercase letters.
let string = "HelloWorld" print(string.splitWordsByCase()) // Prints "Hello World"
Declaration
Swift
func splitWordsByCase() -> String
Return Value
A new string where each word in the original string is delimited by a whitespace.
-
Returns the swap cased version of the string.
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 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 the latinized version of the string without diacritics.
let string = "Hello! こんにちは! สวัสดี! مرحبا! 您好!" print(string.latinized()) // Prints "Hello! kon'nichiha! swasdi! mrhba! nin hao!"
Declaration
Swift
func latinized() -> String
Return Value
The latinized version of the string without diacritics.
-
Retuns the reversed version of the string.
let string = "Hello World" print(string.reversed()) // Prints "dlroW olleH"
Declaration
Swift
func reversedString() -> String
Return Value
The reversed copy of the string.
-
Returns the string without diacritics.
let string = "Crème brûlée" print(string.withoutAccents()) // Prints "Creme brulee"
Declaration
Swift
func withoutAccents() -> String
Return Value
The string without diacritics.