Re: printf
Re: printf
- Subject: Re: printf
- From: "Clark Cox" <email@hidden>
- Date: Thu, 13 Dec 2007 08:55:18 -0800
On Dec 13, 2007 7:51 AM, James Bucanek <email@hidden> wrote:
> 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.
However, every popular text editor/viewer on MacOSX that I can think
of using to view logs is capable of displaying UTF-8 text. By using
NSNonLossyASCIIStringEncoding you're just obfuscating the text.
> 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
>
>
--
Clark S. Cox III
email@hidden
_______________________________________________
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>) |
| >Re: printf (From: James Bucanek <email@hidden>) |