0

I want to print Unicode characters for some special symbol like `,',@,$ so please let me know if there is any method which converts string to unicode characters like \u00e2...

Thanks,

2
  • Refer this link stackoverflow.com/questions/31696142/… Commented Aug 30, 2018 at 8:08
  • Is it your goal to access the characters of a string, or, given a string of unicode characters, to get their unicode descriptors, e.g. given "â" receive "\u00e2"? Commented Aug 30, 2018 at 8:49

1 Answer 1

1

You can get your string unicodeScalars value, convert to hexa and finish padding it with leading zeros:

extension String { var unicodes: [String] { return unicodeScalars.map{ String($0.value, radix: 16) } } func paddingToLeft(maxLength: Int) -> String { return repeatElement("0", count: max(0,maxLength-count)) + self } } 

let str = "\u{00e2}" let hexa = str.unicodes.first! print(hexa.paddingToLeft(maxLength: 4)) // "00e2\n" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.