Checking for non-printable characters

Pickering, John (NORBORD) PICKERIJ@norbord.com
Fri, 17 Sep 1999 10:39:44 -0400


>I have a request from a user to verify that
>all the text fields in the system don't contain
>non-printable characters (i.e. other than
>ASCII codes 32 - 126)

>Is there a reasonably neat approach that
>can be used to check a text field. It seems
>that it probably revolves around the use of
>the CHARACTERS function, but I can't see
>how to code it efficiently.

Here's the code I use in Quick. It removes the weird characters on input --
required here because we run with the "-any" parameter appended to the
termtype. I only remove those characters with decimal values less than a
space because I need to allow diacriticals for French accented characters.
The biggest nuisance characters are probably the horizontal tab (tough to
get new users to abandon its use) and the escape -- this code catches them
both.

This won't help you clean up existing dirty data but it will catch future
occurrences. Perhaps a one time sanitation using Mr. Sharman's pattern
matching would help.

Regards,
JWP

TEMP T-WORK-TEXT      CHAR*50                                         
TEMP T-REMOVED        INT*2

PROCEDURE INTERNAL STRIP-WEIRDIES
BEGIN
  ; strip out any weird characters
  LET T-REMOVED = 0
  LET T-WORK-TEXT = FIELDTEXT
  FOR 50
    IF " " GT T-WORK-TEXT[OCCURRENCE:1]
      THEN BEGIN
         LET T-WORK-TEXT &
           = " " + T-WORK-TEXT[1:OCCURRENCE - 1] &
           + T-WORK-TEXT[OCCURRENCE + 1:50]
         LET T-REMOVED = T-REMOVED + 1
      END
  IF T-REMOVED GT 0
    THEN BEGIN
      IF "" = T-WORK-TEXT[1:T-REMOVED]
        THEN LET FIELDTEXT = T-WORK-TEXT[T-REMOVED + 1:50]
    END
END

PROCEDURE INPUT DESCRIPTION
BEGIN
  IF 0 NE SIZE(FIELDTEXT)
    THEN BEGIN
      DO INTERNAL STRIP-WEIRDIES
      LET FIELDTEXT = LJ(FIELDTEXT)
    END
END


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.