Problem with Left, Right, substring functions and quotes

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
banactp
Participant
Posts: 52
Joined: Tue Feb 22, 2005 2:55 pm

Problem with Left, Right, substring functions and quotes

Post 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
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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?
Eric
Participant
Posts: 254
Joined: Mon Sep 29, 2003 4:35 am

Post by Eric »

I agree with ArndW. These are the values from my routine:

S>"ABCD"
T>ABCD"
U>ABCD
V>ABCD"
banactp
Participant
Posts: 52
Joined: Tue Feb 22, 2005 2:55 pm

Post 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
Post Reply