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

时间:2013-08-26 11:10:54

标签: objective-c cocoa-touch 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
);"];

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

3 个答案:

答案 0 :(得分: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\
);"];

答案 1 :(得分:0)

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);"];

尝试上面的事情

答案 2 :(得分:-2)

代替你的代码
NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return %f",Math.max(
                      document.body.scrollHeight, document.documentElement.scrollHeight,
                      document.body.offsetHeight, document.documentElement.offsetHeight,
                      document.body.clientHeight, document.documentElement.clientHeight
                      )];
希望它会对你有所帮助。