Remove Non-Printing characters

  • Thread starter Thread starter mikebres
  • Start date Start date
M

mikebres

Is there a way to remove non-printing characters from a string?

For example I am getting data from a source that uses the
non-breaking-space character alt-0160 as the delimeter for each field.
When I import the data, all fields have what appears to be an extra
space on the end. This causes problems when I do comparisons with
other sources of data.

Thanks
Mike
 
mikebres said:
Is there a way to remove non-printing characters from a string?

For example I am getting data from a source that uses the
non-breaking-space character alt-0160 as the delimeter for each field.
When I import the data, all fields have what appears to be an extra
space on the end. This causes problems when I do comparisons with
other sources of data.

Thanks
Mike

You can use the Replace() function to replace any specific character,
wherever it appears in the string, with a zero-length string. Like
this:

strMyString = Replace(strMyString, Chr(160), "")

If there are a number of characters you want to remove, you could set up
a string or an array of them and loop through it, calling the Replace
function for each. Or you could write code to remove all characters
that are *not* in a particular set of acceptable characters. In that
case, you would probably want to loop through the source string once,
checking each character and only appending it to a target string if it
is in the "approved" list.
 
Back
Top