You need to sign in to do that
Don't have an account?
Sam Lau
indexOf and Substring
Hi All,
I'm attempting to text parse between two tags within the body of an incoming email. I'm receiving an undeliverable with my tests but can't figure out how to resolve "System.StringException: Ending position out of bounds: 35"
I have my code within the email class as such:
//Parse email
String EmailStartTag = '[Email]';
String EmailEndTag = '[/Email]';
integer Rstart = Body.indexOf(EmailStartTag);
integer Rend = Body.indexOf([EmailEndTag);
integer Rlength = Rend - Rstart;
NPR.Email__c = Body.substring(Rstart, Rlength);
I'm not sure why I'd reach an out of bounds since I'm simply taking the ending position integer and subtracting the starting for the length of the substring. Any pointers would be greatly appreciated.
Sam
I'm attempting to text parse between two tags within the body of an incoming email. I'm receiving an undeliverable with my tests but can't figure out how to resolve "System.StringException: Ending position out of bounds: 35"
I have my code within the email class as such:
//Parse email
String EmailStartTag = '[Email]';
String EmailEndTag = '[/Email]';
integer Rstart = Body.indexOf(EmailStartTag);
integer Rend = Body.indexOf([EmailEndTag);
integer Rlength = Rend - Rstart;
NPR.Email__c = Body.substring(Rstart, Rlength);
I'm not sure why I'd reach an out of bounds since I'm simply taking the ending position integer and subtracting the starting for the length of the substring. Any pointers would be greatly appreciated.
Sam
Remember that substring, in this context, uses indexes, not lengths try the following
I tested in developer console, hence why all the debug statements, but it gives a clearer understanding of the method behaviours.
Note also that the Start Index will be the start point of the String '[Email]' not the start of the actual email address.
HTH
regards
Andrew