[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Forumula Question to replace single quotes

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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. …
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

830 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