Regex: How to remove all non-printable characters - including nulls

  • Thread starter Thread starter active
  • Start date Start date
A

active

I want to remove all non-printable characters - including nulls.

I could extend the following by adding as many printable characters as I can
think of.

But I wonder if there isn't something better.

Like a \something that does it all?

Return Regex.Replace(oStr, "[^\w\.@-]", "").Trim

Then I want to trim the result of white space.



Do you know how to do that?



thanks in advance
 
active said:
I want to remove all non-printable characters - including nulls.

I could extend the following by adding as many printable characters as I can
think of.

But I wonder if there isn't something better.

Like a \something that does it all?

Return Regex.Replace(oStr, "[^\w\.@-]", "").Trim

Then I want to trim the result of white space.

Do you know how to do that?

thanks in advance

No, there is no magic code that includes only printable characters, as
being printable is not a property of the character itself.

What decides if a character is printable or not, is how you are trying
to print it. Different fonts include different characters, so a
character that is printable using one font may be not printable using
another font.
 
How about, replacing all control characters with ""


thanks




Göran Andersson said:
active said:
I want to remove all non-printable characters - including nulls.

I could extend the following by adding as many printable characters as I
can think of.

But I wonder if there isn't something better.

Like a \something that does it all?

Return Regex.Replace(oStr, "[^\w\.@-]", "").Trim

Then I want to trim the result of white space.

Do you know how to do that?

thanks in advance

No, there is no magic code that includes only printable characters, as
being printable is not a property of the character itself.

What decides if a character is printable or not, is how you are trying to
print it. Different fonts include different characters, so a character
that is printable using one font may be not printable using another font.
 
Active,

Are you living in China, please tell us, because those printable characters
are not the same as in Indonesia.

Cor
 
The pattern [\x00-\x1f] matches all control characters including the NUL
character.
How about, replacing all control characters with ""


thanks




Göran Andersson said:
active said:
I want to remove all non-printable characters - including nulls.

I could extend the following by adding as many printable characters as I
can think of.

But I wonder if there isn't something better.

Like a \something that does it all?

Return Regex.Replace(oStr, "[^\w\.@-]", "").Trim

Then I want to trim the result of white space.

Do you know how to do that?

thanks in advance
No, there is no magic code that includes only printable characters, as
being printable is not a property of the character itself.

What decides if a character is printable or not, is how you are trying to
print it. Different fonts include different characters, so a character
that is printable using one font may be not printable using another font.
 
USA

Cor Ligthert said:
Active,

Are you living in China, please tell us, because those printable
characters are not the same as in Indonesia.

Cor

active said:
I want to remove all non-printable characters - including nulls.

I could extend the following by adding as many printable characters as I
can think of.

But I wonder if there isn't something better.

Like a \something that does it all?

Return Regex.Replace(oStr, "[^\w\.@-]", "").Trim

Then I want to trim the result of white space.



Do you know how to do that?



thanks in advance
 
Göran Andersson said:
The pattern [\x00-\x1f] matches all control characters including the NUL

Thanks, that'll do it.


character.
How about, replacing all control characters with ""


thanks




Göran Andersson said:
active wrote:
I want to remove all non-printable characters - including nulls.

I could extend the following by adding as many printable characters as
I can think of.

But I wonder if there isn't something better.

Like a \something that does it all?

Return Regex.Replace(oStr, "[^\w\.@-]", "").Trim

Then I want to trim the result of white space.

Do you know how to do that?

thanks in advance

No, there is no magic code that includes only printable characters, as
being printable is not a property of the character itself.

What decides if a character is printable or not, is how you are trying
to print it. Different fonts include different characters, so a
character that is printable using one font may be not printable using
another font.
 
Works great

thanks

Göran Andersson said:
The pattern [\x00-\x1f] matches all control characters including the NUL
character.
How about, replacing all control characters with ""


thanks




Göran Andersson said:
active wrote:
I want to remove all non-printable characters - including nulls.

I could extend the following by adding as many printable characters as
I can think of.

But I wonder if there isn't something better.

Like a \something that does it all?

Return Regex.Replace(oStr, "[^\w\.@-]", "").Trim

Then I want to trim the result of white space.

Do you know how to do that?

thanks in advance

No, there is no magic code that includes only printable characters, as
being printable is not a property of the character itself.

What decides if a character is printable or not, is how you are trying
to print it. Different fonts include different characters, so a
character that is printable using one font may be not printable using
another font.
 
Back
Top