PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Remove non-printing chars from text file
Remove non-printing chars from text file
Iniciado por guest, 27,jul. 2015 08:52 - 6 respuestas
Publicado el 27,julio 2015 - 08:52
Hi
A client has recently started receiving text files which contain a range of non-printing characters which we need to strip out. The exact characters vary somewhat from file to file so we need a routine to remove ASCII 1 to 31 (excluding TAB,CR & LF) and 127 upwards.

I know we could loop through for each character & replace it but I'm hoping someone has a more efficient way so that we're not looping through the file 100 plus times. We have up to 30 of these files a day to deal with, up to 25Mb in size for each one.

Thanks

David
Publicado el 27,julio 2015 - 09:55
Hi David,

Not tested, but this should do the trick I guess:
CleanString is string = Replace(InitialString, [charact(1), charact(2), Charact(3), ...], "")
Cheers,

Peter H.
Publicado el 27,julio 2015 - 20:46
Hi Peter
Clever idea but no good I'm afraid:(

David
Publicado el 28,julio 2015 - 09:30
Hi David,

I tested it in WD20 with this piece of code and for me it works. The length of the initial string is 3 and the length of the clean string is 0 as it is supposed to be. What version are you using?

InitialString is string = Charact(1)+Charact(2)+Charact(3) Info("Length: "+Length(InitialString)) CleanString is string = Replace(InitialString, [Charact(1),Charact(2),Charact(3)], "") Info("Length: "+Length(CleanString))
Cheers,

Peter H.
Publicado el 28,julio 2015 - 10:57
Me too; I use the Replace function to remove white-space from strings - no problem.
Publicado el 28,julio 2015 - 11:34
you can put it in hex format using BufferToHexa, convert every byte to int using HexaToInt and remove it if the values is in your conditions and revert back from hex using HexaToBuffer.

With replace or this way you don't need to loop thru the file more than once.
Publicado el 28,julio 2015 - 22:01
Hi Peter
The project is in WD17 & that construct throws a syntax error in it. It does work fine in WD20 though so it's either time to update it or run with Paulo's suggestion which does work in WD17.

Thanks guys for the suggestions

David