How to convert a text string to hex string?

后端 未结 3 1946
一向
一向 2021-01-18 14:06

Lets say I have a text string : \"Say Hello to My Little Friend\"

A function should return hex value as:

5361792048656c6c6f20746f204d79204c6974746c6520467269

3条回答
  •  我在风中等你
    2021-01-18 14:45

    Swift 4, Swift 3

    let hex: String = "ABC".unicodeScalars.filter { $0.isASCII } .map { String(format: "%X", $0.value) } .joined() print(hex) // correctly yields 414243

提交回复
热议问题