Solved

Forumula Question to replace single quotes

Posted on 2004-08-06
5
273 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

743 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now