开发者

Special Characters NSString

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; 
             开发者_StackOverflow社区        $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?


You must surrond every row with "".

Like:

NSString *HelloWorld = @"Hello"
                    " World";

What you are doing is:

NSString *HelloWorld = @"Hello
                     World";

which is not valid.

[Edited to correct code display, so example makes sense as line breaks were being removed.]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜