Removing sections from a string in Swift -
all,
if have string :
le7 3jj, 2, bellyache road, sheepshead
how can remove characters , first comma, comes out :
2, bellyache road, sheepshead
do ranges in swift ? want write extension of string :
extension string { func removestringtofirstcomma(input:string) -> string { return } }
you can this:
let str = "le7 3jj, 2, bellyache road, sheepshead" if let firstcomma = str.rangeofstring(",") { let res = str.substringfromindex(advance(firstcomma.startindex, 2)) println(res) }
first, find location of first comma in string. if there, advance index 2 skip on comma , adjacent space character, , take substring starts @ index.
to adapt snippet function, return original string else
branch of conditional (not shown above).
Comments
Post a Comment