如何在目标C中放置转义序列?

Ras*_*ari 0 cocoa-touch objective-c nsstring

我有这个小代码:

NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return     Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);"];
Run Code Online (Sandbox Code Playgroud)

问题是xcode不能将括号和逗号识别为整个字符串.

Ind*_*ore 8

使用\让它多行字符串

NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return     Math.max(\
document.body.scrollHeight, document.documentElement.scrollHeight,\
document.body.offsetHeight, document.documentElement.offsetHeight,\
document.body.clientHeight, document.documentElement.clientHeight\
);"];
Run Code Online (Sandbox Code Playgroud)

  • 原因:如果不转义回车符,则无法将字符串文字包装在多行上. (6认同)