繁体   English   中英

目标C引号和变量

[英]Objective c quotes and variables

我正在尝试做这样的事情:

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

变量charlieImputSelf将作为命令放入终端窗口。 但是我需要将charlieImputSelf放在2个qoutes之间(如上)。 这显然不是正确的方法。 有人可以帮忙吗?

谢谢! 以利亚

为了获得成功,您需要包含文档。 从这里开始 然后去读这个

走上必须在SO上询问有关每一行代码的问题的途径不会成功。

要回答这个问题,您需要stringWithFormat: ::

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

使用NSString+stringWithFormat:方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM