Page 1 of 1

Problem with Left, Right, substring functions and quotes

Posted: Tue May 31, 2005 11:23 am
by banactp
I've tried the following in a Server routine intended for use in a PX sequence:

Code: Select all

S = '"ABCD"'  ; * That's '-"-ABCD-"-'

T = S[Len(S)-1] ; * T = ABCD" at this point

U = T[1,Len(T)-1] ; * U should = ABCD
V = T[1,Len(T)]   ; * V should = ABCD"
Now when I run this code, string V = ABCD" as expected, but string U = AB. Not only is the trailing double quote trimmed from U, but also the C and D. The same behavior is presented when Left() and Right() syntax is used.

(Note that the correct result can be obtained in this case by simply setting U = S[2,Len(S)-2] but keep in mind that's just a solution to this specific instance of a more general problem - how to manipulate strings with quotes in and around them.)

Has anyone encountered this problem with quotes in strings before? If so, how did you work around it?

TIA

tpb

Posted: Wed Jun 01, 2005 12:35 am
by ArndW
banatcp,

I cut and pasted your code into a function and, lo and behold, the value of U is, as expected, ABCD.

I don't know where your problem is coming from, but your code as posted will produce the expected results.

What does
X= '"Hello World"'
PRINT X[1,LEN(X)-1] print out on your machine?

Posted: Wed Jun 01, 2005 4:08 am
by Eric
I agree with ArndW. These are the values from my routine:

S>"ABCD"
T>ABCD"
U>ABCD
V>ABCD"

Posted: Wed Jun 01, 2005 5:41 am
by banactp
Well, it looks like this one will remain a mystery :?

The problem must have been specific to the particular function I was testing the code snippet in, because this morning I cut and pasted my own code into a different routine and ... no problem.

Unfortunately, I no longer have the piece of code that I originally used for testing, so I can no longer reproduce the behavior. I guess that's not all that bad...

Thanks,

tpb