What is the more elegant way to remove all characters after specific character in the String object in Swift

Here is a way to do it:

var str = "str.str"

if let dotRange = str.rangeOfString(".") {
    str.removeRange(dotRange.startIndex..<str.endIndex)
}

Update
In Swift 3 it is:

var str = "str.str"

if let dotRange = str.range(of: ".") {
  str.removeSubrange(dotRange.lowerBound..<str.endIndex)
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)