You need to sign in to do that
Don't have an account?
cyberdynebot
Remove text from String between characters which appear more than once
I have a String value from a Long Text field that contains Name/Email values. I need to extract only the names separated by a semi colon when there are multiple entries (no semi colon in the text if only one name) using Apex/String methods into another variable. Essentially strip out anything that begins with the pipe delimiter ' | ' and ends with '.com' (will always end in '.com').
Single value scenario:
John Test | jtest@none.com
Expected:
John Test
Multiple values:
Scott Rogers | srogers@none.com; Mike Smith | msmith@none.com; Matt White | mwhite@none.com
Expected:
Scott Rogers; Mike Smith; Matt White
I've tried using substring/left/right but my approach may not be correct as I'm getting a null value each time and I also believe I need an array/list to grab each entry if multiple matches.
Example of test:
s1 = 'Scott Rogers | srogers@none.com; Mike Smith | msmith@none.com; Matt White | mwhite@none.com';
String s2 = s1.right(1).substringBetween(' |','.com');
Single value scenario:
John Test | jtest@none.com
Expected:
John Test
Multiple values:
Scott Rogers | srogers@none.com; Mike Smith | msmith@none.com; Matt White | mwhite@none.com
Expected:
Scott Rogers; Mike Smith; Matt White
I've tried using substring/left/right but my approach may not be correct as I'm getting a null value each time and I also believe I need an array/list to grab each entry if multiple matches.
Example of test:
s1 = 'Scott Rogers | srogers@none.com; Mike Smith | msmith@none.com; Matt White | mwhite@none.com';
String s2 = s1.right(1).substringBetween(' |','.com');
Hope this will help.
Thanks
Surya