You need to sign in to do that
Don't have an account?
raj123
How to check whether the string contains singlequote, double quote, and blacklash (\)
How to check whether the string contains singlequote, double quote, and blacklash (\)
i am not able to use the sring contains function for these 3 things.
for a string contains single quote, use backslash to escape, for example string abccc'd, will need to write code as:
String s = 'abccc\'d';
system.debug(s.contains('\'')); ===> will print out as true
double quote should not bother, just take it as normal character, string abccc"d, just write as:
String s='abccc"d';
system.debug(s.contains('"')); ==> will print out as true
backslash, same use another backslash to escape, for example abccc\d, will need to write code as:
String s = 'abccc\\d';
system.debug(s.contains('\\')); ===> wil print out as true
Hi Coco sdyney,
thanks for the fast reply
what i am actuallu doing is
if(substring.contains('/'')) { substring = substring.substringBefore('/''); }
and i am getting the following error
Save error: expecting a right parentheses, found ')) { substring = substring.substringBefore('
for all of then i wan to break the string till this character appear
escape with backslash \, not slash /
change your code to:
if(substring.contains('\'')) { substring = substring.substringBefore('\''); }
Checked both ways still not able to do it.
results in true for all cases:
You could also do this with Matcher and Pattern classes