Focal Point
problem with string

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5491063072

February 07, 2008, 10:42 AM
roby
problem with string
Hi,
I have field in focus type is A50.
In this string are of the special characters or symbols(for example */@ รง ec.)
I must replace this characters with spaces. It 'is possible?
thanks for any help!!!
February 07, 2008, 10:56 AM
TexasStingray
Check out the CTRAN function




Scott

Short answer - Yes

Look into CTRAN function or GETTOK in conjunction with SUBSTR


Leah
Roby
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.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
I 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.


Alan.
WF 7.705/8.007
Great use of FUNCTIONs Alan!! Good One

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10