Objective c quotes and variables
I'm trying to do something like this:
NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:@"tell application \"terminal\" to do script " charlieImputSelf " in front window"];
[sendCharlieImput executeAndReturnError:nil];
The variable charlieImputSelf is going to be put into the terminal window as a command. BUT I need to put charlieImputSelf in between 2 qoutes (like above). This i开发者_开发技巧s obviously not the correct way. Can someone help?
Thanks! Elijah
To be successful, you'll need to embrace the documentation. Start here. Then go read this.
Going down the path of having to ask a question on SO about every line of code is not going to lead to success.
To answer this question, you want stringWithFormat:
:
[NSString stringWithFormat: @"some random string \"with quotes\" and %@ word in the middle.", @"this"];
Use NSString
's +stringWithFormat:
method:
NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Terminal\" to do script %@ in front window", charlieImputSelf]];
精彩评论