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!
  • Students Click Here

*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.

Students Click Here


Extract between two characters

Extract between two characters

Extract between two characters

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.

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:


...the following formula would return:


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

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.


RE: Extract between two characters

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

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


RE: Extract between two characters



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

Hope this helps.


RE: Extract between two characters

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


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!

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