ios - How to get substring of String in Swift? -


this question has answer here:

if want value nsstring "😃hello world😃", should use?

the return value want "hello world".

the smileys can string. need regexp this.

there's more 1 way it.

first: string in swift 1.2 bridged nsstring answer : how substring of nsstring?

second: answer deal emoticon characters too.

var s = "😃hello world😃" let index = advance(s.startindex, 1) // index string.index 2nd glyph, “h”  let endindex = advance(s.startindex, 12) let substring=s[index..<endindex] // here got "hello world"  if let emojirange = s[index...s.endindex].rangeofstring("😃") {     let substring2 = s[index..<emojirange.startindex] // here "hello world" } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -