2010-07-02 56 views
1

我试图做这样的事情:目标C报价和变量

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:@"tell application \"terminal\" to do script " charlieImputSelf " in front window"]; 
[sendCharlieImput executeAndReturnError:nil]; 

变量charlieImputSelf将被放入终端窗口的命令。但我需要把charlieImputSelf置于2个字符之间(如上所述)。这显然不是正确的方法。有人可以帮忙吗?

谢谢! 利亚

回答

3

使用NSString+stringWithFormat:方法:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Terminal\" to do script %@ in front window", charlieImputSelf]]; 
10

要取得成功,你需要拥抱的文档。 Start here。然后去read this

在关于每行代码都不得不提出SO问题的道路上不会取得成功。

要回答这个问题,你想stringWithFormat:

[NSString stringWithFormat: @"some random string \"with quotes\" and %@ word in the middle.", @"this"];