I'm trying to find a way to check if a substring causes an out of bounds error in an If statement
This is what I have got so far but if the original string has less than 8 characters after substring then I will get an error.
String s = 'This is M-000034'; // if this was M-0023 it will cause error
Boolean replied = false;
String subs = 'M-';
If(s.containsIgnoreCase(subs)){
String s1 = s.toUpperCase();
String s2 = s1.deleteWhitespace();
system.debug(s1);
system.debug(s2);
replied = true;
system.debug(replied);
Integer r = s2.indexOf(subs);
String caseNumber = s2.substring(r, r+8);
system.debug(caseNumber);
}else {
system.debug('nothing');
}
Thanks in advance!