You need to sign in to do that
Don't have an account?
Drew Gehman 18
Finding Parentheses using a string class
I am trying to return the string found between parentheses in a field. Something like this:
String s1 = 'My favorite color is xYellowy'; String s2 = s1.substringBetween('x','y'); System.assertEquals('Yellow', s2);If I substitute square brackets for x and y everything works well. When using traditional parentheses, I thought I would need to escape the parentheses, like this:
String s1 = '(Yellow)'; String s2 = s1.substringBetween('\\(','\\)'); System.assertEquals( 'Yellow', s2);But that didn't work either. I bet I am 90% there, but I am missing something,
Try this:
Let me know if it helped you!
Thanks,
AG
All Answers
Try this:
Let me know if it helped you!
Thanks,
AG
You don't need to escape the parentheses.
Just try:
works perfectly.
C'est la vie. Thanks all.