Solved

Forumula Question to replace single quotes

Posted on 2004-08-06
5
303 Views
Last Modified: 2012-06-22
Gurus,

I am using the following formula to replace one character for another character:

local numbervar i;
local stringvar char;
local stringvar str;
stringvar string := {Orders.Ship Via};


for i := 1 to length(string)
do
if string[i] = ' '
then str := str + 'a'
else if string[i] = 's'
then str := str + 'B'
else str := str + string[i];

str


It is working well except I need to replace:
'
for the letter
b

I get an error message that says:
"The matching ' for this string is missing
OK"


What am I missing?  What is the correct syntax to use to avoid the error message?

Thanks in advance,

Steve
0
Comment
Question by:SStroz
  • 2
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
bdreed35 earned 200 total points
ID: 11740170
As an immediate solution, qualify your text lieterals with double quotes rather than a single quote.

Your formula that you posted would look like this:

local numbervar i;
local stringvar char;
local stringvar str;
stringvar string := {Orders.Ship Via};


for i := 1 to length(string)
do
if string[i] = " "
then str := str + "a"
else if string[i] = "s"
then str := str + "B"
else str := str + string[i];

str

You can now check for a ' like this

if string[i] = "'"

This has a set of double quotes surrounding a single quote.

Can you explain exactly why you are doing this?  I think that it could be streamlined especially if you are replacing alot of characters.  You could even post the whole formula as well.
0
 
LVL 7

Author Comment

by:SStroz
ID: 11790482
bdreed35,

Thanks for responding.  I'm sorry I didn't see your reply sooner - I didn't get my update e-mail from experts-exchange.  ??

The formula is posted below.  The final goal is to connect two tables to create a report.  Unfortunately, the unique key to join the tables uses the algorithm below.

As you may tell I'm a novice programmer and a friend helped me get this far.  I was wondering if a case statement might make more sense but didn't know how to write it.

The formula as it stands now:


local numbervar i;
local stringvar char;
local stringvar str;
stringvar string := {WC_ONE2MANY.ContactID};


for i := 1 to length(string)
do
if string[i] = " "
then str := str + "a"
else if string[i] = "'"
then str := str + "b"
else if string[i] = "!"
then str := str + "c"
else if string[i] = "@"
then str := str + "d"
else if string[i] = "#"
then str := str + "e"
else if string[i] = "$"
then str := str + "f"
else if string[i] = "%"
then str := str + "g"
else if string[i] = "^"
then str := str + "h"
else if string[i] = "&"
then str := str + "i"
else if string[i] = "*"
then str := str + "j"
else if string[i] = ":"
then str := str + "k"
else if string[i] = ";"
then str := str + "l"
else if string[i] = '"'
then str := str + "m"
else if string[i] = "/"
else str := str + string[i];

Do you have any suggestions for improvement.

Thanks in advance,

Steve
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 11790547
CASE and IF are essentially the same to the compiler, so it probably won't make any difference in speed though it might be easier to modify later.

Do the special characters have to map in that order or can the mapping be changed?
ie does " " --> a and ' --> b or can you use a different mapping?

If adifferent mapping can be used then some simple math can be done rather than the complex if-then-else construct.

mlmcc
0
 
LVL 7

Author Comment

by:SStroz
ID: 11797935
Gurus,

My last follow-up to this question.  I am running into a case sensitivity issue in this formula.

In the following code:

if string[i] = " "
then str := str + "a"
else if string[i] = "'"
then str := str + "b"
else if string[i] = "!"

I would like a "a" replaced with a "'"'; however, I don't want a "A" replaced with a "'". (Capital Case).

Can this be done?

Thanks in advance,

Steve
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 11798361
I think you meant to add this to your other question.

I don't have my Crystal references so i am not sure but if you use the VB syntax you should avoid the case.

I just checked the Crystal 7 help.  CR7 has a strcmp function to compare 2 strings.  It is a case-sensitive search.

strcmp(str1,str2) - returns 0 if equal, -1 str1 less than, +1 str1 greater.

mlmcc
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question