[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# Forumula Question to replace single quotes

Posted on 2004-08-06
Medium Priority
320 Views
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?

Steve
0
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
• 2
• 2

LVL 28

Accepted Solution

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

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.

Steve
0

LVL 101

Expert Comment

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

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?

Steve
0

LVL 101

Expert Comment

ID: 11798361

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

Question has a verified solution.

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

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
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 episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
###### Suggested Courses
Course of the Month14 days, 8 hours left to enroll