我需要带一个值为
的字符串String s = "Patient first name must contain at least one letter(a-zA-Z).
May contain numbers, ,(comma), -(dash), '(apostrophe),
/(forward-slash), \(backslash), &(ampersand) or .(period)"
但是当我在Eclipse中使用它时,它会告诉我无效的转义序列。谁能在这帮助我?
提前致谢!
答案 0 :(得分:3)
你有两个问题:
所以你可能想要这样的东西:
String s = "Patient first name must contain at least one letter(a-zA-Z)."
+ " May contain numbers, ,(comma), -(dash), '(apostrophe),"
+ " /(forward-slash), \\(backslash), &(ampersand) or .(period)";
...但也可能有换行符。 (目前尚不清楚。)
请参阅Java语言规范的sections 3.10.5 and 3.10.6以查看字符串文字中的有效内容。
答案 1 :(得分:0)
试试这个:
String s = "Patient first name must contain at least one letter(a-zA-Z).May contain numbers, ,(comma), -(dash), '(apostrophe),/(forward-slash), \\(backslash), &(ampersand) or .(period)";//no multiline. and escape backslash \
System.out.println(s);