Search code examples
objective-cmacosutf-8printfnslog

How to display UTF8 string in OS X Terminal


I can't believe I couldn't find a solution to this very simple issue. I have a command line tool in Objective C, and need to display UTF8 strings (with non-English characters) in the console. I can't use NSLog as it also display process information, PID, timestamp etc. too. printf doesn't handle non-English characters well.

How can I print non-English characters in the Terminal, without any timestamps? Am I missing something really obvious here, or is such an extremely simple task really non-trivial in OS X?

I've tried:

printf: Doesn't display non-English characters.

NSLog: Displays PID/timestamp, which I don't want.

DLog (from https://stackoverflow.com/a/17311835/811405): Doesn't display non-English characters.


Solution

  • This works just fine:

    printf("%s\n", [@"Can Poyrazoğlu" UTF8String]);