February 07, 2008, 10:57 AM
LeahShort answer - Yes
Look into CTRAN function or GETTOK in conjunction with SUBSTR
February 07, 2008, 06:52 PM
susannahRoby
slighly longer answer...
example
you want to change all instances of '#' to a blank ' ';
First you need to know what the numeric value is of the '#'
I'll assume you're on a windows server (thus ASCII characters) and not on an IBM Main or midframe (thus EBCIDIC characters)
DEFINE FILE CAR
POUND/I4 WITH CAR=BYTVAL('#','I4');
SPACE/I4 WITH CAR= BYTVAL(' ','I4');
END
TABLE FILE CAR
PRINT POUND SPACE
IF RECORDLIMIT IS 1
END
..and you'll see that the numeric value for the # is 35 and for the SPACE its 32.
then in your own data file,
DEFINE FILE myfile
MYOUTPUT/A80=CTRAN( 80, MYINPUT , 35 , 32, 'A80');
..changes all instances of 32 to 35.
For reference, just because you're in Roma,
@ 64
& 38
- 45
' 39
, 44
" 34
. 46
| 124
/ 47
+ 43
_ 95
[ 60
] 62
( 40
) 41
{ 91
} 93
= 61
$ 36
* 42
.. the opposite of BYTVAL function is the HEXBYT function, takes a numeric value and tells you the character. Download the USING FUNCTIONS manual, if you haven't yet.
and por favour, edit your signature block in your profile on this board to tell us your operating system, your versions, etc.
February 08, 2008, 02:57 AM
Alan BI always found the problem with this was that the code got lengthy, particularly as I prefer STRREP over CTRAN.
A solution I came up with was to use DEFINE FUNCTION, so you can do something like this:
DEFINE FUNCTION cleanStr (string/A50,search/A1)
cleanStr/A50 = STRREP(50,string,1,search,1,' ',50,'A50');
END
DEFINE FILE CAR
OLDSTRING/A50 WITH COUNTRY = 'A string"that?needs@some|characters#replacing';
NEWSTRING/A50 = cleanStr(cleanStr(cleanStr(cleanStr(cleanStr(OLDSTRING,'#'),'|'),'@'),'?'),'"');
END
TABLE FILE CAR
PRINT OLDSTRING NEWSTRING
BY COUNTRY
IF COUNTRY EQ ENGLAND
END
I am not sure how deep you can nest this, but it seems to be able to go pretty deep.
February 08, 2008, 04:54 AM
Tony AGreat use of FUNCTIONs Alan!!
T