?
Solved

Forumula Question to replace single quotes

Posted on 2004-08-06
5
Medium Priority
?
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
bdreed35 earned 800 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 101

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 101

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 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