更新时间:2023-12-03 19:51:46
有两种方式在多行分割字符串:
There are two ways to split strings over multiple lines:
在C所有线可以被分成使用\\多行
All lines in C can be split into multiple lines using \.
普通C:
char *my_string = "Line 1 \
Line 2";
目标-C:
NSString *my_string = @"Line1 \
Line2";
有一个更好的办法,只是为字符串工作。
There's a better approach that works just for strings.
普通C:
char *my_string = "Line 1 "
"Line 2";
目标-C:
NSString *my_string = @"Line1 "
"Line2"; // the second @ is optional
第二种方法比较好,因为没有包括很多的空白。然而,对于一个SQL查询,这两个都是可能的。
The second approach is better, because there isn't a lot of whitespace included. For a SQL query however, both are possible.
请注意:用#define,你必须添加一个额外的\\来连接两个字符串:
NOTE: With a #define, you have to add an extra '\' to concatenate the two strings:
普通C:
#define kMyString "Line 1"\
"Line 2"