INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Extract between two characters

Extract between two characters

(OP)
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)

RE: Extract between two characters

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

RE: Extract between two characters

(OP)
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

RE: Extract between two characters

Try:

CODE

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

Hope this helps.

Cheers
Pete

RE: Extract between two characters

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

-LB

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close