Reputation: 36098
I'd like to trim /
from the beginning and end of a string in Swift. Is there anything built or for this or what's a good way to do this?
Upvotes: 2
Views: 523
Reputation: 70098
I like to use stringByTrimmingCharactersInSet
in such cases, with a custom character set (here just "/"):
let original = "/word/"
let result = original.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "/"))
Result: "word"
Upvotes: 1