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

时间:2022-06-05 00:02:51

I have this small code:

我有这个小代码:

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

the problem is xcode doesnt recognize the parentheses and commas as a whole string.

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

3 个解决方案

#1


-2  

Replace you code by

替换你的代码

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

hope it will help you.

希望它能帮助你。

#2


8  

Use \ to make it multi line string

使用\使其成为多行字符串

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

#3


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

try above thing

尝试上面的事情

#1


-2  

Replace you code by

替换你的代码

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

hope it will help you.

希望它能帮助你。

#2


8  

Use \ to make it multi line string

使用\使其成为多行字符串

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

#3


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

try above thing

尝试上面的事情