代码之家  ›  专栏  ›  技术社区  ›  Ian Turner

如何处理cocoa中的警告未知转义序列“\040”

  •  1
  • Ian Turner  · 技术社区  · 15 年前

    我在Cocoa应用程序中运行的一些Applescripts中出现了以下警告:

    http://emberapp.com/splash6/images/unknown-escape-sequence-error/sizes/m.png

    我已经尝试了所有我能想到的方法来消除这个错误,比如完全重写它,从另一个没有警告的类似脚本复制和粘贴等等,但是我无法摆脱它。谁能告诉我哪里出了问题吗。

    NSString *theCellRefScript = [NSString stringWithFormat:@"tell application \"Numbers\"\n\
                                                    tell document 1 \n\
                                                    tell sheet \"%@\" \n\
                                                    tell table \"%@\" \n\
                                                    set value of cell \"%@\" to \%@\ \n\
                                                    end tell \n\
                                                    end tell \n\
                                                    end tell \n\
                                                    end tell ", theSheet, theTable, theCell, [theDistributionValues objectAtIndex:k]];
    
    4 回复  |  直到 15 年前
        1
  •  8
  •   Jeff    15 年前

    Objective-C与所有现代C编译器一样,如果字符串文字被空格分隔,它会自动连接起来。与其使用多行斜杠,不如使用:

     NSString *theCellRefScript = [NSString stringWithFormat:@"tell application \"Numbers\"\n"
                                                    "tell document 1\n"
                                                    "tell sheet \"%@\ \n"
                                                    "tell table \"%@\ \n"
                                                    "set value of cell \"%@\" to \%@ \n"
                                                    "end tell\n"
                                                    "end tell\n"
                                                    "end tell\n"
                                                    "end tell", theSheet, theTable, theCell, [theDistributionValues objectAtIndex:k]];
    
        2
  •  4
  •   Graham Perks    15 年前

    在最后一个反斜杠后面的一行末尾有一个尾随空格。它认为你是在试图逃离一个空间,而不是连接线。

        3
  •  0
  •   Ian Turner    15 年前

    发现问题后,有一个游荡空间就行了,开始设置单元格的值。工作版本为:

    set value of cell \"%@\" to \%@\\n\
    
        4
  •  0
  •   Sam Azer    11 年前

    这让我抓狂,因为我真的看不见。在我的例子中,结果很简单:在我的帮助文本中,我写了一个特定的选项将跳过所有空格-我举了一个例子,

    "\ "
    

    "\"\ \""
    

    "\"\\ \""
    

    HTH公司