remy boys remy boys - 6 months ago 22
iOS Question

Parse a string with specific condition

how can i trim my string which is in this forms e.g. :

to this


what i want is to remove the remaining characters from second
slash (from backward)

i can use
but i dont know how to specify here the condition that i want

let trimmedString = myString.stringByTrimmingCharactersInSet(
NSCharacterSet.whitespaceAndNewlineCharacterSet() // what here in my case ??

the above is for removing the white spaces , but that not the case here

p.s. if my question is not clear enough then let me know i'll explain it in a little bit more deep


Since the string is an URL get the path components, remove anything but the last 2 items and join the items with the slash separator.

if let url = NSURL(string:""), pathComponents = url.pathComponents {
  let trimmedString = pathComponents.suffix(2).joinWithSeparator("/")