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

Changing a description string 1

Status
Not open for further replies.

Rachel30

Programmer
Mar 1, 2005
95
GB
hello,

I have a string at the end of the sting it might have the word UK or it might Have UK EU or it might have loaded I would like to delete anything after these words ie if the product description is:-

Product UK I would like to just see the word product if the description is product product Loaded. I would like to just see the words product product. Any help I would be greatfull Thanks Rachel
 
Hi there,

You could use a formula which is like this

if instr({Field},"UK") > 0 then
replace({Field},"UK","") else
if instr({Field},"Loaded") > 0 then
replace({Field},"Loaded","") etc...

or you could use

if instr({Field}, "Product UK") > 0 then
replace({Field},"Product UK","Product} else
if instr({Field},"Product Product Loaded") > 0 then
replace({Field},"Product Product Loaded","Product Product") etc...

You can repeat this until you have covered all you possible options.

HTH

-steve
 
Hi,

Thanks for your help. I have used the replace one it works but I want to delete all the text after uk

so for example

I have

Product 1 uk
Product 2 uk eu
Product 3 uk eu ww

I wanted to delete any text after uk not just the UK any ideas thanks. Cheers Rachel
 
Hi Rachel,

Ok try this formula:

whileprintingrecords; Just replace {Field} with your field.

stringvar name;
numbervar counter;

if instr({Field},"Product UK") > 0 then counter:= instr({Field},"Product UK") else
if instr({Field},"Product Product") > 0 then counter:= instr({Field},"Product Product");

name:=left({customer.Customer Name},counter);

name;

HTH

~ Steve
 
Hi,

Thanks for your help. I am having a go but I don't understand the:-

name:=left({customer.Customer Name},counter);

Do I put my field name there. Thanks
 
Basically whats happening is is that the instr function is searching the string field to find the values that you want i.e "Product UK".

When it finds this in the string it gives it a number so for
"Product UK" it would return 10 (it does include spaces).

Then when the value has been stored you can do a left() on that field based on the returned number. So for the example of Product UK which returns the value 10 the left statement in effect is doing the following

left({field},10) so all that your seeing on the report is the string which is only displaying 10 characters long (counting from the left)

Does that help any?

-Steve
 
and yes you do put your name field where i've got

{customer.Customer Name};

forgot to change that to {Field}


-Steve
 
Hi,

OK I have this so far which works:-

whileprintingrecords;

stringvar name;
numbervar counter;

if instr({spCyclePolicyDetails;1.Type Of Cover},"-") > 0 then counter:= instr({spCyclePolicyDetails;1.Type Of Cover},"-")-2 else
if instr({spCyclePolicyDetails;1.Type Of Cover},"(loaded)") > 0 then counter:= instr({spCyclePolicyDetails;1.Type Of Cover},"(Loaded)")-2;

name:=left({spCyclePolicyDetails;1.Type Of Cover},counter);

name;

The only problem is I have two other descriptions that I want to leave alone as they have nothing on the end. I was going to do a not instr but I could not get that to work. Cheers Rachel.
 
Whats the ones that you want to leave alone?

Can you give an example please?

-Steve
 
Hi,

The ones I want to ignore are:-

Roadcare standalone
StudentGuard Cycle
Platinum Care

Thanks
 
Asuming that these are the only ones you want to ignore you can do the following

whileprintingrecords;

stringvar name;
numbervar counter;

if instr({spCyclePolicyDetails;1.Type Of Cover},"Roadcare standalone") > 0 then name:= ({spCyclePolicyDetails;1.Type Of Cover} else

if instr({spCyclePolicyDetails;1.Type Of Cover},"StudentGuard Cycle") > 0 then name:= ({spCyclePolicyDetails;1.Type Of Cover} else

if instr({spCyclePolicyDetails;1.Type Of Cover},"Platinum Care") > 0 then name:= ({spCyclePolicyDetails;1.Type Of Cover} else
if instr({spCyclePolicyDetails;1.Type Of Cover},"-") > 0 then counter:= instr({spCyclePolicyDetails;1.Type Of Cover},"-")-2 else
if instr({spCyclePolicyDetails;1.Type Of Cover},"(loaded)") > 0 then counter:= instr({spCyclePolicyDetails;1.Type Of Cover},"(Loaded)")-2;

name:=left({spCyclePolicyDetails;1.Type Of Cover},counter);

name;


HTH
 
Thanks for your help. Cheers Rachel Why didn't I think of that.
 
Hi,

I am using the same formula for two diffrent reports it the same thing the field names are different. I have added my code and I am getting a string is required here. I have tried putting brackets round it with no joy.

Can you see where I am goinng wrong ?

whileprintingrecords;

stringvar name;
numbervar counter;

if instr({spQuoteNew;1.sProductType},"Roadcare standalone") > 0 then name:= {spQuoteNew;1.sProductType} else
if instr({spQuoteNew;1.sProductType},"StudentGuard Cycle") > 0 then name:= {spQuoteNew;1.sProductType} else
if instr({spQuoteNew;1.sProductType},"Platinum Care") > 0 then name:= {spQuoteNew;1.sProductType} else
if instr({spQuoteNew;1.sProductType},"-") > 0 then counter:= instr({spQuoteNew;1.sProductType},"-")-2 else
if instr({spQuoteNew;1.sProductType},"(loaded)") > 0 then counter:= instr({spQuoteNew;1.sProductType},"(Loaded)")-2;

name:=left({spQuoteNew;1.sProductType},counter);

name;

Cheers Rachel
 
Try this

whileprintingrecords;

stringvar name;
numbervar counter;

if instr({spQuoteNew;1.sProductType},"Roadcare standalone") > 0 then counter:= instr({spQuoteNew;1.sProductType},"Roadcare standalone") else
if instr({spQuoteNew;1.sProductType},"StudentGuard Cycle") > 0 then counter:= instr({spQuoteNew;1.sProductType},"StudentGuard Cycle") else
if instr({spQuoteNew;1.sProductType},"Platinum Care") > 0 then counter:= instr({spQuoteNew;1.sProductType},"Platinum Care") else
if instr({spQuoteNew;1.sProductType},"-") > 0 then counter:= instr({spQuoteNew;1.sProductType},"-")-2 else
if instr({spQuoteNew;1.sProductType},"(loaded)") > 0 then counter:= instr({spQuoteNew;1.sProductType},"(Loaded)")-2;

name:=left({spQuoteNew;1.sProductType},counter);

Let me know how this one goes.

-Steve
 
Thanks it worked. I can see what you was doing now. Thanks again Rachel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top