main logo
Subject: Re: Strip non-ASCII characters
Author: =?ISO-8859-1?Q?Ricardo_Ar=E1oz?=
Posted: 2007/07/31 13:32:37
 
View Entire Thread
New Search


Bill Kressbach wrote:
> The code is for monitoring the Emergency Alert System (EAS) for a radio
> station. Sometimes a little noise from the receiver will add a few bytes of
> data to the beginning of the message while the receiver is trying to lock
> up. This latest one is 00 00 FF 00 FF 00 00 (HEX). These characters will
> sometimes confuse the software causing strange results. So I need to remove
> them. I am a little concerned about the amount of time required to remove
> them but I could try a modification of Ed's code by keeping anything between
> 20 and 127.

If time is an issue you might clock these too and use the fastest (the
second one assumes the foreign characters appear only at the beginning
of the string) :

LPARAMETERS targetStr

local bad, ii
bad = ""
FOR ii = 0 TO 19
bad = bad + CHR(ii)
ENDFOR
FOR ii = 128 TO 255
bad = bad + CHR(ii)
ENDFOR

RETURN STRTRAN(targetStr, bad)

lparameters targetStr

local ii
for ii = 1 to len(targetStr)
if not between(ASC(substr(targetStr, ii, 1)), 20, 127)
return substr(targetStr, ii+1)
endif
endfor

>
> Bill
>
>
>> Actually there will be no non-ascii characters.
>> A string is a list of bytes, ascii is just a way of interpreting them,
>> so if you decide the string is in ascii format, every character will be
>> an ascii character.
>
>
>
>



 
©2007 =?ISO-8859-1?Q?Ricardo_Ar=E1oz?=
<-- Prior Message New Search Next Message -->