Re: printf
Re: printf
- Subject: Re: printf
- From: James Bucanek <email@hidden>
- Date: Thu, 13 Dec 2007 08:51:20 -0700
One additional tip:
If you're writing log-file-like output and want it as readable
ASCII text, consider using -[NSString
cStringUsingEncoding:NSNonLossyASCIIStringEncoding] instead of
-[NSString UTF8String].
While UTF8 is great for machine-to-machine transport,
NSNonLossyASCIIStringEncoding encodes non-ASCII characters using
a simple ASCII escape sequence (\0134) that makes reading or
parsing the file using plain ol' text editors/viewers easy. Even
better, NSNonLossyASCIIStringEncoding is bidirectional like
UTF8, so if you ever have to read the text back in as data use
the same encoding; NSNonLossyASCIIStringEncoding will parse the
escape sequences and convert them back to their original Unicode values.
Clark Cox <mailto:email@hidden> wrote (Thursday, December
13, 2007 8:03 AM -0800):
On Dec 13, 2007 6:40 AM, Roland Silver <email@hidden> wrote:
Is there a function in one of the frameworks that's like printf, but
allows the output conversion '%@' in its template? Eg
likePrintf("%@ is allowable", @"this string");
or better:
likePrintf(@"%@ is allowable", @"this string");
No, but it's relatively easy to write your own:
int likePrintf(NSString *format, ...) {
va_list args;
va_start(args, format);
NSString *output = [[NSString alloc] initWithFormat: format
arguments: args];
va_end(args);
int result = printf("%s", [output UTF8String]);
[output release];
return result;
}
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Re: printf (From: "Clark Cox" <email@hidden>) |