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

REPLACE FUNCTION PROBLEM

Status
Not open for further replies.

shaunk

Programmer
Aug 20, 2001
402
AU
The value I have in Customer.Region = "Mendoza".

I wish to replace the "M" with a null value.

The function is :

Replace ({Customer.Region},"M", "")

I am expecting the function to return "endoza" but it is returning all nulls.

Any clues ??
 
Hi,

You are telling Crystal to return nothing to you when you use:

Replace ({Customer.Region},"M", "")

Have you tried:

Replace ({Customer.Region},"Mendoza", "endoza")

alley
 
To add "Hmmmmm" level.
I created a formula of
Replace("Mendoza","M", "") and got the dersired "endoza"

I then used the replace in an existing report to test the null replacement. I too got blank fields.

There seems to be some sort of bug with the replace function (at least in version 8.0)

Using the following format:
replace(length of string,length to replace,length of replacement) resulting length of string returned.

replace(10,5,1) = 3
would be a string of 10 character, looking for 5 specific characters, replaceing with 1 character resulted in a string 3 charatcers long

some of my test results (along with 1st example):
replace(10,2,1) = 8 (should be 9)
replace(15,5,4) = 13 (should be 14)
replace(15,5,3) = 9 (should be 13)
replace(10,5,3) = 8 (CORRECT)

replace doesn't seem to like the length of the replacing string to be shorter than the replaced string.

To get your Replace ({Customer.Region},"M", "") to work use
trim(Replace ({Customer.Region},"M", " "))
Mike

 
Thanks for the amount of work you put in on that one.
At last I have found a bug !!!!!!!! rather than finding
I was using Crystal badly.

I will use the replace with space and the trim function.
 
What was the difference in your test Mbarron??

field data versus fake data?


Weird...I tested it too and got the same result ....HOWEVER... I created a string variable and it worked fine.

Try this:

stringVar replaceString := "";
Replace ({Customer.Region},"M", replaceString);


this worked in my case....Jim
 
I'm assuming you're referring to the Replace(##,##,##)=##
Orininally I used field data, but the following is fake date (but real results)
The only differences, was the length of the strings that I was replacing and length of the replacement string.

As an example:
@alpha
"ABCDEFGHIJKLMNO"

@replace_string1
Replace({@alpha},"ABC","Z")

Should be: "ZBCDEFGHIJKLMNO"
returned: "ZDEGF"

@replace_string2
Replace({@alpha},"ABCD","ZYX")
Should be:"ZYXEFGHIJKLMNO"
returned:"ZYXEFGHIJKLM"


My theory is that it has something to do with the lengths of what is being looked for and the replacement. Your solution works (according to my theory) because the replacement (the whole stringvar being considered as one "unit") is equal in size or smaller than the string being replaced.





Mike

 
As I said...if the replace string is an assigned variable instead of a quoted string....even a null seems to work fine, but when the replace string is a quoted string the problem happens as you describe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top