You need to sign in to do that
Don't have an account?
Nelson-Benavides
Extract specific text from a String
Hi there,
I already have all the code working, but at the end I don't need to insert all the content of the String variable.
Suppose you have a String variable called: temp --- and this variable contains the following text:
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
abc abc abc
defghi
jklmnopq 1234 56789
"Start"
More text More text More text More text More text More text More text More text More text More text More text
"End"
1234567890123456 Text Text Text Text Text Text Text Text
More Text Text Text Text Text Text
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
I only need to "extract" or "insert" the text that is between "Start" and "End" instead of inserting everything.
How do I do this? What method(s) and/or Functions could I use?
Thanks in advance.
--Nelson.
I already have all the code working, but at the end I don't need to insert all the content of the String variable.
Suppose you have a String variable called: temp --- and this variable contains the following text:
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
abc abc abc
defghi
jklmnopq 1234 56789
"Start"
More text More text More text More text More text More text More text More text More text More text More text
"End"
1234567890123456 Text Text Text Text Text Text Text Text
More Text Text Text Text Text Text
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
I only need to "extract" or "insert" the text that is between "Start" and "End" instead of inserting everything.
How do I do this? What method(s) and/or Functions could I use?
Thanks in advance.
--Nelson.
temp.Substring(temp.indexof('start')+4,temp.indexof('end')+3);
All Answers
temp.Substring(temp.indexof('start')+4,temp.indexof('end')+3);
I ended up implementing the one with INDEXOF and it worked out perfectly.
Thanks again!
Kevin, thanks for your support, even 5 years later it helped to me to obtain a specific value from an URL:
hope this helps someone :)
I wanted to extract from this String: '/practice/*/prescriber'
I did this: String foo = req.requestURI.substringAfter('/practice/').substringBefore('/prescribers);
and it worked perfectly for me :D
Id accountId = ((request.requestURI.subStringAfter('Accounts/')).subStringBefore('/contacts'));
accountId will have 0015g000016K4KBAA0