特殊字符 NSString
我有一个 NSString 我试图声明,这样我就可以将它用作苹果脚本。这是代码:
NSString *script1 = @"do shell script /usr/bin/php -r ($mac = \"g1:ag:g3:cg:gg:eg\"; $porttemp = \"9\"; $ip = \"255.255.255.255\";
$mac_bytes = explode(\":\", $mac);
$mac_addr = \"\";
for ($i=0; $i<6; $i++)
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = \"\";
for ($i=0; $i<6; $i++) /*6x 0xFF*/
$packet .= chr(255);
for ($i=0; $i<16; $i++) /*16x MAC address*/
$packet .= $mac_addr;
$port = $porttemp;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port);
socket_close($sock);
);"
我面临的问题是 xcode 说我没有终止它并给出了一大堆错误。知道我该如何解决它或者我有什么问题吗?
I have a NSString I am trying to declare so I can use it as an applescript. here is the code:
NSString *script1 = @"do shell script /usr/bin/php -r ($mac = \"g1:ag:g3:cg:gg:eg\"; $porttemp = \"9\"; $ip = \"255.255.255.255\";
$mac_bytes = explode(\":\", $mac);
$mac_addr = \"\";
for ($i=0; $i<6; $i++)
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = \"\";
for ($i=0; $i<6; $i++) /*6x 0xFF*/
$packet .= chr(255);
for ($i=0; $i<16; $i++) /*16x MAC address*/
$packet .= $mac_addr;
$port = $porttemp;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port);
socket_close($sock);
);"
The Problem I am facing it that xcode says I am not terminating it and gives a whole bunch of errors. Any idea how I can solve it or have I got anything wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每一行都必须用“”括起来。
就像:
你正在做的是:
这是无效的。
[编辑以更正代码显示,因此示例有意义,因为换行符被删除。]
You must surrond every row with "".
Like:
What you are doing is:
which is not valid.
[Edited to correct code display, so example makes sense as line breaks were being removed.]