Mega Code Archive

 
Categories / Delphi / Examples
 

Visiblechars

VISIBLE characters from both the normal ASCII range 0 to 127 and also form the 'extended ASCI' range 128 to 255 are in the following groups: (see CaseNotes.txt) Chrs 33 to 126 145 to 151 161 to 171 173 to 174 176 to 181 183 to 255 So, the simplest way to look for visible chars is to use a set variable like this: type TVisibleChars = set of Char; var VisibleChars: TVisibleChars; begin VisibleChars := [Chr(33)..Chr(126),Chr(145)..Chr(151),Chr(161)..Chr(171), Chr(173)..Chr(174),Chr(176)..Chr(181),Chr(183)..Chr(255)]; if (ch in VisibleChars) then doSomething; end; AND IF YOU'VE GOT AN ARRAY WITH ALL MANNER OF STUFF IN, INCLUDING CRs AND LFs THAT WILL SCREW THINGS UP, THEN DECLARE YOUR SET VARIABLE AS ABOVE (BUT ADD THE SPACE CHARACTER, number 32) AND THEN DO THIS... y := 0; for x := 0 to chunkSize do begin if (tempArray[i] in visibleChars) then begin visibleArray[y] := tempArray[x]; Inc(y); end; end; visibleArray[y] := #0;