Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 1, 2012, 02:33 PM   #1
LinusR
macrumors regular
 
Join Date: Jan 2011
Replace " with \"

Good evening,

I would like to use an AppleScript. This AppleScript contains names with quotation marks (""). But to use them in AppleScript I have to use \". Now I tried to replace them by
Code:
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement
But how shall I declare the quotation mark? My first try looked like this:

Code:
NSString *name = [[textField stringValue] stringByReplacingOccurrencesOfString:@"\"" withString:@"\""];
But because of the (\) Objective-C thinks I want to replace " with ". Can anyone help? My AppleScript looks like this:

Code:
NSString *script = [NSString stringWithFormat:@"tell application \"iTunes\" \n play (every track of playlist 1 whose name is \"%@\") \n end tell", name];
iTunes doesn't play the track when the track title contains quotation marks. So they have to be replaced by (\"). Does anyone know a solution?

Thanks in advance,

Linus

EDIT: Wrong orthography
LinusR is offline   0 Reply With Quote
Old Jan 1, 2012, 05:09 PM   #2
rossipoo
macrumors regular
 
Join Date: Jun 2009
\\ will insert a backslash into a string.

For example:
[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]
rossipoo is offline   1 Reply With Quote
Old Jan 2, 2012, 05:45 AM   #3
LinusR
Thread Starter
macrumors regular
 
Join Date: Jan 2011
Quote:
Originally Posted by rossipoo View Post
\\ will insert a backslash into a string.

For example:
[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]
Thanks, this worked awesome!

Thanks for your help,

Have a nice day,

Linus
LinusR is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Replace "left" GPU with a second "Right" GPU for two SSDs is nMP? JesterJJZ Mac Pro 29 Jan 3, 2014 09:33 AM
Replace 2011 27" iMac and 2011 13" Macbook Air with 15" rMBP? weezin MacBook Pro 7 May 1, 2013 08:23 AM
Anyone use their personal MBP to "replace" their work-issued Windows Laptop? hellfire88 MacBook Pro 20 Mar 19, 2013 09:36 AM
13" MacBook Air + Cinema Display to replace 27" iMac dmw16 MacBook Air 17 Dec 7, 2012 10:19 PM
Looking to replace my cracked MBP 13" screen cover myself. Question about "glass"... stopandlisten MacBook Pro 0 Jun 20, 2012 01:53 AM

Forum Jump

All times are GMT -5. The time now is 09:00 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC