#Text Filtering
5 messages in this thread
Greetings, I need help! I am writing a small ascii terminal program and I am
having problems filtering out control codes and other nonsensical characters
before displaying the read buffer from the serial port. I have been able to
strip bit 8 from the chars in the buffer but am stuck with control codes
intermixed with the text. How do I get rid of unneccessary control codes?
Thanx, Tom.
>How do I get rid of unneccessary control codes?
Not fully clear on your questions. Do you mean
Perhaps with a switch statement? A table? An array?
Hi Greg, I mean I need to remove the control codes from the read stream that I
don't need. I am trying to get plain ascii text out of the stream. Any
suggestions?
Tom.
Most C compilers have a function called isprint that returns TRUE for printable
ascii characters and FALSE for everything else.
Peter Wade
Autopiloting from London, England
> How do I get rid of unnecessary control codes?
Depends on what form your data is in, what the purpose of the control codes
is, what you mean by 'get rid of' ….
Generally: you identify a control code by the fact that it's in the range
0-31 or 128-159, specifically excepting whatever end-of-line signals you want
to catch (10=NewLine, 13=Return, possibly TAB and also the delete character).
So: the general approach is: 1. Detect and bypass any special control
codes you want to detect, such as those named above; 2. temporarily knock off
the high bit of the character with something like AND 07Fh; 3. if the result
of the previous operation is less than 32 (020h), it's a control code and you
can throw it out. 4. Don't forget to restore the character to its original
state (before step 2 mangling) if you want to use it.
–Jim