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

Not sure how to use the replace function 1

Status
Not open for further replies.

eo

MIS
Apr 3, 2003
809
Hi

I am doing webstats reports showing which search phrase was enetered to bring a user to our website. The format in the referer address is for example ...tertiary+education (where + represents a space), or %22tertiary+education%22 (where %22 represents "), and so on (there is a wjhole list of codes).
What I need to do is strip the codes out of the search phrase, and thought of doing this with the replace function in Crystal, BUT...
To do a single replace is fine, e.g. replace ({field}, '+', ' ') and this works fine. BUT this is not the only code that must be replaced, and as soon as I add another variable, errors occur. I have tried the following:
replace ({field}, '+', ' ') or
replace ({field}, '%22', '"')

replace ({field}, '+', ' ') and
replace ({field}, '%22', '"')

replace ({field}, '+', ' ') else
replace ({field}, '%22', '"')

But no luck. I know this is possible as I have seen it done before, but the layout of my formula is incorrect. Can someone help?

EO
 
Try nesting them:

Replace ( Replace ({field}, '+', ' ') , '%22', '"')

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Tips and Tricks / Guide to Crystal in VB
- tek@kenhamady.com
 
thanks that worked well
 
I have encountered anoter problem!!! I have many codings that must be replaced by their true meanings (approx 27), the instructions as above worked well, but only as far as two variables were concerned. As soon as I included a third, the field size all of a suddent only showed 30 characters.

Here is my actual formula (which worked well):
Replace (Replace ({@11 Search phrase to LCase}, '%2c', ','), '%22', '"')

As soon as I added a 3rd variable, the actual formula field's only shows the first 30 characters:
Replace( Replace (Replace ({@11 Search phrase to LCase}, '%2c', ','), '%22', '"'), '+', ' ')

Any idea why this is happening?

EO
 
What version are you using? I had the same problem with the replace function with 8.0. Specifically, it would truncate the field when I tried to replace spaces with no spaces. I believe this has been corrected in higher versions.

-LB
 
Hi lbass
I am using CR8
I have however found a way of overcomming the problem by adding CStr infront of the whole formula, it will therfore look something like:
CStr (Replace( Replace (Replace ({@11 Search phrase to LCase}, '%2c', ','), '%22', '"'), '+', ' '))
It seems to have solved the problem
EO
 
Replace in v8 had some issues. I seem to remember that you couldn't replace a character with an empty string ( "" ) until v8.5, but the CSTR really surprises me. I just nested 5 and didn't get truncation in v8.5.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Tips and Tricks / Guide to Crystal in VB
- tek@kenhamady.com
 
Another annomilie in this regard!!!

I have a set of characters that must be replaced with other characters and hence the formula: CStr (Replace( Replace (Replace ({@11 Search phrase to LCase}, '%2c', ','), '%22', '"'), '+', ' '))
BUT there are MANY more that must simply be replaced by a space. To write a formula like the one above would take agens and a lot of effort. So I have done that basic formula for the set of characters, how can I also include 'if it does not all within that set' then 'space'? I have tried adding ..., '', ' ') as another replace criteria, but that did not seem to work. Any ideas?

EO
From a cold Hertfordshire :-(
 
Can you provide sample data and the expected outcome.... There might be a better way to do this.

Reebo
UK

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
- Albert Einstein (1879-1955)
 
EO,
The cstr() saved me a bunch of headaches.

Thanks for pointing it out.

Mike
 
I am doing webstat reports, and its a report that shows the search phrase used when a user was refered to our site using a search engine. Lets use the following sentence as a phrase entered into the search phrase:

"How to do this, mate?"

The phrase is represented in a search engine referal URL as follows:

%22How+to+do+this%2C+mate%3F%22

On the report I need to show it in the same format as the original search phrase. Hence using the replace function where:

%22 represents "
+ represents a space
%2C represents a comma, and
%3F represents ?

The replace formula would look like:

CStr (Replace (Replace( Replace (Replace ({@11 Search phrase to LCase}, '%22', '"'), '+', ' '), '%2C', ','), '%3F', '?'))

The problem is that there are 100's of these definitions, and all I am interested in, are the main ones, like ! " £ % , space, ' etc.
For all others I would only like to show a space, as opposed to the code that the search engine generates. And to write a formula that will take ALL the possible codes into account will be a near impossible task.

Using the replace function was the logical option, but unless I can replace the anomilies with a space, it will be flawed.

Any help is appreciated.

EO
:)
 
building the formula like :

Local StringVar HTML := '%22&How+to+do+this%2C+mate%3F%22';
HTML := Replace(HTML,'%22','"');
HTML := Replace(HTML,'+',' ');
HTML := Replace(HTML,'%2C',',');
HTML := Replace(HTML,'%3F','?');
HTML := Replace(HTML,'&','');

Makes it easier to troubleshoot, also this works ok, just replace the item in bold with you field name....

What would be really handy would be an inbuilt html translator...

Reebo
UK

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
- Albert Einstein (1879-1955)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top