Re: Odd display of percent character
Re: Odd display of percent character
- Subject: Re: Odd display of percent character
- From: Chris Paveglio <email@hidden>
- Date: Mon, 13 Feb 2012 11:32:45 -0800 (PST)
I was thinking it had something to do with the % formatter, but wasn't sure how to "escape" it, or if there was something different about NSAlert. I totally understand now how it works, as the "informativeTextWithFormat" automatically reads the % as another format placeholder.
Thanks Kyle, Ken and Keary!
----- Original Message -----
From: Kyle Sluder <email@hidden>
To: Chris Paveglio <email@hidden>
Cc: Cocoa Dev List <email@hidden>
Sent: Monday, February 13, 2012 1:22 PM
Subject: Re: Odd display of percent character
On Mon, Feb 13, 2012 at 9:04 AM, Chris Paveglio
<email@hidden> wrote:
> I'm having an issue with the percent character being displayed as random numbers in an NSAlertPanel (modal). My app has an ivar, "fullString", including the usual property/synthesize getters and setters, there is nothing special about it. fullString is bound to an NSTextField where a user might type "10% off all shoes", or put some text that contains dollar signs or percent signs. Later another method will validate if it's a web address or plain text and display an alert if it's not a web address. At this point I use the usual -stringWithFormat and put the "fullString" text in with some other descriptive text. But if fullString contains a percent character, then the NSAlert displays something like "10254458745ff all shoes". Why is the percent character being turned into some numbers, and it also seems to lop off the space and letter o as well? Using ampersand, dollar sign, and number symbol all display properly.
NSAlert takes a format string. Therefore you must take care to never
ever pass user input as part of the format string.
NSString *fullString = managedObj.fullString;
NSString *informativeText = [NSString stringWithFormat:@"The
fullString %@ is invalid.", fullString];
NSAlert *alert = [NSAlert alertWithMessageText:…
informativeTextWithFormat:@"%@", informativeText];
Note the use of "%@" as the format argument.
--Kyle Sluder
_______________________________________________
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