ios - how to split a string like char and number separately in swift -


i facing 1 issue how split number , string in same string , display it. clear lets take example have string like,

mystring = "mh04ed7897" 

i want output

output = mh-04-ed-7897 

i new in swift. try

let startindex  = number.startindex.advancedby(4)         let laststr:string = number.substringfromindex(startindex)         let initialstr:string = number.substringtoindex(startindex)          nslog("%@   %@", laststr,initialstr)            let startinitialindex  = initialstr.startindex.advancedby(2)          let initialstart:string = initialstr.substringtoindex(startinitialindex)          let initialfinish:string = initialstr.substringfromindex(startinitialindex)          print("initalstart :\(initialstart)")         print("initialfinish :\(initialfinish)")          let startlastindex  = laststr.endindex.advancedby(-4)          let laststart:string = laststr.substringfromindex(startlastindex)          let replaced = laststr.stringbyreplacingoccurrencesofstring(laststart, withstring: "")          print("replace:\(replaced)")         // let lastfinish:string = laststr.substringtoindex(startfirstindex)          print("laststart :\(laststart)") 

you output enter image description here


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -