Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to display a part of a string in a data field
shortstack
I am trying to extract a substring of another data element and display in a new data element. The value of of this data element looks like this: CVGP-MECH-1000 or CVGP-LAB-1000. I would like to extract MECH or LAB and display that in a new data element. With these being different lengths, I need to find a way to use the dashes as cue to pull the text. There are about 200 records that I need to be able to pull that middle text out of. Please help. Thanks
Find more posts tagged with
Comments
thuston
[col].substring( [col].indexOf("-"), [col].lastIndexOf("-") )
I can never remember, but you may have to +1 or -1 either of the indexes to prevent also getting the '-' char.
pricher
Yes, you need to add 1 to the first argument, as in:
var mytext = "MECH-ABC-123";
mytext = mytext.substring(mytext.indexOf("-") + 1,mytext.lastIndexOf("-"));
shortstack
Thanks to both of you, it worked.