Tilde Character in String

Dawn M

Member
Progress V9.1 on Windows XP and HP-UX 11.

I have a string with the tilde "~" character embedded in it.

Example:

"12345678~0011~001"


The "~001" is a delimiter that separates 2 values ("12345678" and "1"). This string is passed into a program that needs to parse these 2 values out and use them in a message statement.

The problem is, no matter what I try, I can't "locate" the tilde in the string. I've tried index, lookup, can-do and replace, using both CHR(126) (the ASCII value of ~) and "~~". Nothing works.

If the string read "12345678~~0011~~001", I can successfully parse out the values. But, since I can't find "~" in the string, I can't add the extra "~" needed to parse the string.

Any ideas?!

PS: Does anyone else think that Progress' new version of the Knowledge Base (now Knowledge Center) sucks?
 
Unfortunately tilde is a "special" character and will always be treated as "take the next character and do not interpret it".

Basically in the string the ~ doesn't REALLY exist - it just is there to make sure that the next character is read properly. It will be forcing the next 3 digits to be read as an Octal character 001

Have a go with Replace(Str, "~001", "New Seperator")
 
Where is the string located? Could you possibly replace the ~ with an operating system command before passing the string to Progress?
 
You are right that the ~ character cannot be found in a string. In Progress, it is a special character. But if your delimiter is not '~' alone but '~001', then you should be able to extract .

I have tried sample code below and it works - V91.D


DEF VAR mx AS CHAR init "12345~001YY~001ZZ".
DEF VAR k AS INT.
DEF VAR j AS INT.
DEF VAR m1st AS CHAR.
DEF VAR m2nd AS CHAR.

DISP mx FORMAT "x(30)" .
DO:
j = INDEX(mx,"~001").
m1st = SUBSTR(mx,1,j - 1).

k = INDEX(mx,"~001",j + 1).
m2nd = SUBSTR(mx,j + 1,k - j - 1).

DISP j LABEL "1st-Pos" m1st LABEL "Extract1"
k LABEL "2nd-Pos" m2nd LABEL "Extract2"
WITH 1 COL.
END.

Note that ~001 is treated as 1 character not 4.

Regards
Skc
 
Yup, that did the trick. I could have SWORE that I tried index among my many "gyrations" thru this problem.

THANKS!
 
Back
Top