How to Trim a String in Swift based on a character -


i trim string, can extract filename, preceded "_" (underscore). best way this?

https://s3.amazonaws.com/brewerydbapi/beer/rxi2ct/upload_ffapfl-icon.png

i result ffapfl-icon.png

you can use string method rangeofstring:

let link = "https://s3.amazonaws.com/brewerydbapi/beer/rxi2ct/upload_ffapfl-icon.png" if let range = link.rangeofstring("_") {     let filename = link.substringfromindex(range.endindex)     print(filename)  // "ffapfl-icon.png\n" } 

xcode 8 beta 3 • swift 3

if let range = link.range(of: "_") {     let filename = link.substring(from: range.upperbound)     print(filename) // "ffapfl-icon.png\n" } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -