String
Concatenate: "abc" + "efg"
Check if string is empty: nameOfString.isEmpty
Get last four letters
let lastFour = theString.suffix(4)
check if first four letters is http:
if theString.hasPrefix("http")
Get letter at an index:
Placing a variable in between a string:
"ABCD \(nameOftheVariable)"
New line:
let trimmedString = string.trimmingCharacters(in: .whitespaces)
Check if string is empty: nameOfString.isEmpty
Get last four letters
let lastFour = theString.suffix(4)
check if first four letters is http:
if theString.hasPrefix("http")
Get letter at an index:
func getLetterAtIndex(str: String, location: Int) -> String
{
let index = str.index(str.startIndex, offsetBy: location)
return String(str[index])
}
Placing a variable in between a string:
"ABCD \(nameOftheVariable)"
New line:
\n
Removing trailing and leading whitespace
Get rid of all white spaces:
Create a new swift file. Add the following below:
extension String {
func removingWhitespaces() -> String {
return components(separatedBy: .whitespaces).joined()
}
}
Comments
Post a Comment