function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sathishsfdcsathishsfdc 

how to check for '' in apex

String s = '\'';
system.debug('s contains single quote='+s.contains('\''));
String s2 = '"';
system.debug('s2 contains double quote='+s2.contains('"'));
String s3 = '\\';
system.debug('s3 contains backslash='+s3.contains('\\'));


String s4 = '''';
system.debug('s2 contains double quote='+s2.contains(''''));

The attachement would give more details....thanks
User-added image
Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
String s = '\'';
system.debug('s contains single quote='+s.contains('\''));
String s2 = '"';
system.debug('s2 contains double quote='+s2.contains('"'));
String s3 = '\\';
system.debug('s3 contains backslash='+s3.contains('\\'));


String s4 = '\'\'';
system.debug('s4 single quote quote='+s2.contains('\'\''));

String s5 = '""';
system.debug('s5 contains double quote='+s2.contains('""'));
User-added image

Let us know if this will help you

THanks
Amit Chaudhary