Re: Escaping white space in an NSString
Re: Escaping white space in an NSString
- Subject: Re: Escaping white space in an NSString
- From: Sherm Pendley <email@hidden>
- Date: Thu, 21 May 2009 09:15:23 -0400
On Thu, May 21, 2009 at 1:23 AM, Bruce Johnson <email@hidden>wrote:
> I have a unix path in an NSString via [[NSBundle bundleForClass: [self
> class]] pathForResource: etc.. etc..
> The problem is that the path has white spaces scattered in the string.
That's not normally a problem.
> And I need to pass the unix path to a CLI application. The CLI app
> croaks on the white spaces (for obvious reasons)
The reasons are not at all obvious. Whitespace is only a problem if you type
the whole command as a single string to a shell, which will split the string
on unescaped whitespace to find a command and arguments. Quoted strings are
also not split, so quoting user-provided arguments when they're used in
shell scripts is easier than escaping them.
If you're passing the arguments using NSTask, whitespace is not a problem.
In fact, adding unnecessary quotes and/or escapes to NSTask arguments will
*create* a problem, because NSTask - like everything *except* the command
shell - uses arguments exactly as given, without processing quotes or
escapes.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
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