Search code examples
iphoneiosnsstringnsstringencoding

Convert special character like $ to hexadecimal


I am working on an iOS application. In this application I am trying to convert NSString to hexadecimal. But in some cases NSString contains special $, ¥, etc. This is where I am facing problem. These characters don't convert to hexadecimal.

Is there any way to convert special characters to hexadecimal?


Solution

  • Convert the string to NSData

    [NSString dataUsingEncoding:]
    

    Then using the data object you can output any base you want: octal, hex, decimal, binary.