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

Replace Character in a String

Status
Not open for further replies.

cr7user

MIS
May 25, 2010
13
GB
Hi,

I would like to replace the letters A and B in the fields below with the actual welding wire types:

if {LABOR_TICKET.DESCRIPTION} = "A/PN9705" then output should be "WB6105S(FCAW)/PN9705"
else if {LABOR_TICKET.DESCRIPTION} = "B/PN9405" then output should be "WB6316L(FCAW)/PN9405"

We use crytal reports version 7 and it doesn't have replace function. Kindly Help.

TIA
 
Should still have left() and mid()

If left({LABOR_TICKET.DESCRIPTION}, 1) = "A" then
"WB6105S(FCAW)" &mid({LABOR_TICKET.DESCRIPTION}, 2,7) else


.... repeat for B


Ian
 
Hi Ian,

Tried your suggestion, but it comes up with a boolean is required here error before "WB6105S(FCAW".
Also length of mid is not a constant and it could be anything between 5 to 25 characters. How do I define the string length? Kindly help.

TIA
 
If left({LABOR_TICKET.DESCRIPTION}, 1) = "A"

is a boolean

Just set mid to full length of field
mid({LABOR_TICKET.DESCRIPTION}, 2,25) else

If its a VARCHAR it will only return what is there.

Ian
 
Ian,

I am a learner. This is the formula I am using and it still comes up with boolean is required here error.

if left ({LABOR_TICKET.DESCRIPTION}, 1) = "A" then ("TUBROD 14.05 ROOT WIRE FCAW") and mid ({LABOR_TICKET.DESCRIPTION},2,50)
else if left ({LABOR_TICKET.DESCRIPTION}, 1) = "B" then ("WB 6121S FILLER WIRE (FCAW)") and mid({LABOR_TICKET.DESCRIPTION},2,50)

I am stuck.
 
You have to use & when joining text "and" in Crystal syntax means something completly different.

Also you have wrapped in (), you can't do that either!

if left ({LABOR_TICKET.DESCRIPTION}, 1) = "A" then "TUBROD 14.05 ROOT WIRE FCAW"&mid ({LABOR_TICKET.DESCRIPTION},2,50)
else if left ({LABOR_TICKET.DESCRIPTION}, 1) = "B" then "WB 6121S FILLER WIRE (FCAW)"&mid({LABOR_TICKET.DESCRIPTION},2,50)

If & does not work in CR7 try +

Ian
 
Thanks Ian. That worked like a treat. + sign did the trick.
 
Just a comment. If you don't specify the second argument in the mid(,,), the function will read to the end of the field.

if left ({LABOR_TICKET.DESCRIPTION}, 1) = "A" then
"TUBROD 14.05 ROOT WIRE FCAW" & mid ({LABOR_TICKET.DESCRIPTION},2) else
if left ({LABOR_TICKET.DESCRIPTION}, 1) = "B" then
"WB 6121S FILLER WIRE (FCAW)" & mid({LABOR_TICKET.DESCRIPTION},2)

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top