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:
 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
let trimmedString = string.trimmingCharacters(in: .whitespaces)

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

Popular posts from this blog

Setting up a playground

Go to another page