0

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.

Community
  • 1
  • 1
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

3 Answers3

2

The macro you've tried to use depends on CFShow which doesn't print Unicode characters but only their escape codes. More information regarding this behaviour here.

So you could either use something else for your macro instead of CFShow to print to console without any timestamps or you could use an NSLog replacement library I wrote, Xcode Logger and use its XLog_NH logger which prints only the output without any other information.

Community
  • 1
  • 1
Razvan
  • 4,122
  • 2
  • 26
  • 44
2

This works just fine:

printf("%s\n", [@"Can Poyrazoğlu" UTF8String]);
Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
1

Using stdio:

puts([@"Can Poyrazoğlu" UTF8String]);

Using write:

const char* example = [@"Can Poyrazoğlu" UTF8String];
write(STDOUT_FILENO, example, strlen(example));