I have a NSString with hex string like "68656C6C6F" which means "hello".
Now I want to convert the hex string into another NSString object which shows "hello". How to do that ?
I have a NSString with hex string like "68656C6C6F" which means "hello".
Now I want to convert the hex string into another NSString object which shows "hello". How to do that ?
extension String {
func hexToString()-> String {
var newString = ""
var i = 0
while i < self.count {
let hexChar = (self as NSString).substring(with: NSRange(location: i, length: 2))
if let byte = Int8(hexChar, radix: 16) {
if (byte != 0) {
newString += String(format: "%c", byte)
}
}
i += 2
}
return newString
}
}