×
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!
  • 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

Remove text between two points within a string

Remove text between two points within a string

Remove text between two points within a string

(OP)
I'm finding this somewhat troublesome to solve - How can I remove a value within a string, with the position continuing to change?  The value will always start with 'Camp, ending with ')' or '),' Example  Camp(anytxtvalue), or  Camp(anytxtvalue) 

Data before:
Home, Camp(alpha), Billing, Mailing
Billing, Mailing, Home
Camp(beta), Mailing, Home
Mailing, Billing, Camp(sq)

Looking for after:

Home, Billing, Mailing
Billing, Mailing, Home
Mailing, Home
Mailing, Billing

Thank you for any help given

RE: Remove text between two points within a string

This seems to work. Replace your string field with this formula:

whileprintingrecords;
stringvar x := {table.string};
stringvar array y := split(x,",");
numbervar i;
numbervar j := ubound(y);
stringvar z := "";
stringvar a;
numbervar b;
stringvar c;

if instr(x,"Camp")>=1 then (
a := mid(x,instr(x,"Camp"));
b := instr(a,")");
c := mid(x,instr(x,"Camp"),b)
);
for i := 1 to j do (
redim preserve y[j];
if instr(x,"Camp")=0 then
z := y[i] else
if trim(y[i])<>c then
z := z + y[i]+"," else
z := z
);
if instr(z,",")>=1 then
left(z, len(z)-1) else
z;

-LB

RE: Remove text between two points within a string

(OP)
Thank you, LB for your assistance - If I may trouble you.  If the string doesn't have 'Camp' within the string, it only returns the last value.  Example, if the string is:

Secondary, Mailing, Billing

Or

Billing, Historical, Directory

The formula will return only:

Billing

and

Directory

Can the entire string be displayed?

Kind regards -

RE: Remove text between two points within a string

Sorry--I didn't check for that option when testing. Change the middle section of the formula to:

for i := 1 to j do (
redim preserve y[j];
if instr(x,"Camp")=0 or
trim(y[i])<>c then
z := z + y[i]+"," else
z := z
);

-LB

RE: Remove text between two points within a string

(OP)
LB - That is a fine bit of code.. Thank you very much. I need to sit down and work it out.

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! Already a Member? Login

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