Reputation: 3578
I need to take a string with values as
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)"
But when I take it in Eclipse, it says to me Invalid Escape Sequence. Can anyone help me here?
Thanks in advance!
Upvotes: 0
Views: 1348
Reputation: 12797
Try this:
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);
Upvotes: 0
Reputation: 1502985
Well you've got two problems:
So you probably want something like:
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)";
... but possibly with line breaks as well. (It's not clear.)
See sections 3.10.5 and 3.10.6 of the Java Language Specification to see what's valid in a string literal.
Upvotes: 3