Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract between two characters

Status
Not open for further replies.

ramz_003

Technical User
Dec 11, 2016
2
US
Hello All,
I'm trying to extract data between two characters.
Example XXX.XXXX_

I'm able to extract the first part of the string its the second part (.XXXX_ ). In my example I can extract if the characters are there but not all will have a character at the end. Some have them for character fill in. So the code that doesn't have a character at the end I get an error message.
Here is my code so far.

whileprintingrecords;
numbervar v_firstdash;
numbervar v_secondunderscore;

v_firstdash := instr({Budget.Group2},"-");
v_secondunderscore := instr(mid({Budget.Group2},v_firstdash + 1),"_");


mid({Budget.Group2},v_firstdash + 1, v_secondunderscore - 1)
 
Your example doesn't show a dash, but if your data looks like this:

abcd-efg_
hij-klmn

...the following formula would return:

abdeefg
hijklmn

left({Budget.Group2},instr({Budget.Group2},"-")-1) +
(
if instr({Budget.Group2},"_")=0 then
mid({Budget.Group2},instr({Budget.Group2},"-")+1) else
extractstring({Budget.Group2},"-","_")
)

If this doesn't meet your needs, you should show a sample of data that includes all of the variations that might occur in the data.

-LB
 
Thanks for the reply lbass

Not looking to combine just extract between the dash and underscore
After period is 5 characters and some will be 5 and some will have the underscore to fill in
123-abcd
123-abc_

Looking for 'abc' or abcd (if has 5 characters others just removing underscore)

Thanks
 
Try:
Code:
Replace(Split({Budget.Group2},'-')[2],'_', '')

Hope this helps.

Cheers
Pete
 
Then just omit the first line of my formula, and start with the "if" statement.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top