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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove text between two points within a string

Status
Not open for further replies.

crytalbria

Technical User
Mar 25, 2020
7
GB
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
 
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 else
if trim(y)<>c then
z := z + y+"," else
z := z
);
if instr(z,",")>=1 then
left(z, len(z)-1) else
z;

-LB
 
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 -
 
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)<>c then
z := z + y+"," else
z := z
);

-LB
 
LB - That is a fine bit of code.. Thank you very much. I need to sit down and work it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top