What is the more elegant way to remove all characters after specific character in the String object in Swift?
Suppose that I have the following string:
Quite a compact way would be:
var str = "str.str"
str = str.componentsSeparatedByString(".")[0]
Another option you might be interested in, which works for your example 'str.str' but doesn't fit your specification is:
str = str.stringByDeletingPathExtension
// Returns a new string made by deleting the extension (if any, and only the last)
// from the `String`