473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Feb 25 '07 #1
7 34588
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.

--
Göran Andersson
_____
http://www.guffa.com
Feb 25 '07 #2


How about, replacing all control characters with ""
thanks


"Göran Andersson" <gu***@guffa.comwrote in message
news:OX*************@TK2MSFTNGP04.phx.gbl...
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.

--
Göran Andersson
_____
http://www.guffa.com

Feb 25 '07 #3
Active,

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

Cor

" active" <ac**********@a-znet.comschreef in bericht
news:O0*************@TK2MSFTNGP05.phx.gbl...
>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


Feb 25 '07 #4
The pattern [\x00-\x1f] matches all control characters including the NUL
character.

active wrote:
How about, replacing all control characters with ""
thanks


"Göran Andersson" <gu***@guffa.comwrote in message
news:OX*************@TK2MSFTNGP04.phx.gbl...
> 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.

--
Göran Andersson
_____
http://www.guffa.com


--
Göran Andersson
_____
http://www.guffa.com
Feb 25 '07 #5
USA

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:OD**************@TK2MSFTNGP02.phx.gbl...
Active,

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

Cor

" active" <ac**********@a-znet.comschreef in bericht
news:O0*************@TK2MSFTNGP05.phx.gbl...
>>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



Feb 26 '07 #6

"Göran Andersson" <gu***@guffa.comwrote in message
news:OJ**************@TK2MSFTNGP02.phx.gbl...
The pattern [\x00-\x1f] matches all control characters including the NUL
Thanks, that'll do it.
character.

active wrote:
>How about, replacing all control characters with ""
thanks


"Göran Andersson" <gu***@guffa.comwrote in message
news:OX*************@TK2MSFTNGP04.phx.gbl...
>> 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.

--
Göran Andersson
_____
http://www.guffa.com



--
Göran Andersson
_____
http://www.guffa.com

Feb 26 '07 #7
Works great

thanks

"Göran Andersson" <gu***@guffa.comwrote in message
news:OJ**************@TK2MSFTNGP02.phx.gbl...
The pattern [\x00-\x1f] matches all control characters including the NUL
character.

active wrote:
>How about, replacing all control characters with ""
thanks


"Göran Andersson" <gu***@guffa.comwrote in message
news:OX*************@TK2MSFTNGP04.phx.gbl...
>> 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.

--
Göran Andersson
_____
http://www.guffa.com



--
Göran Andersson
_____
http://www.guffa.com

Feb 26 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Thomas Mlynarczyk | last post by:
Which is the simplest way to remove all whitespace from a string? Is there a simpler method than a regex replace? Or how can I tell a regex pattern to ignore all whitespace in my subject string?...
9
by: chris | last post by:
is there a quick and easy way to check a string for non numeric characters ? i have thought of making a routine to check each character to confirm it is 0 - 9 but was wondering if there was a...
1
by: Jeff Thies | last post by:
I need to remove non digits from a number. I thought I could do this: var phone='22-p67s82'; var re=/\D/g; phone=phone.replace(re,''); alert(phone) yields: 22-p67s82
2
by: Dan Shanyfelt MCAD | last post by:
I am new to regex, but I am assuming it provides a better way to do what I need. I want to write a custom trim functions that will remove all occurrences of a non-whitespace character from the...
10
by: Chance Hopkins | last post by:
I'm trying to match a set of matches after some initial text: mytext: "something" "somethingelse" "another thing" "maybe another" (?:mytext: )(?<mymatch>{1,1}+{1,1}+)+ I only get the last one...
0
by: jg | last post by:
If I need to reuse regex pattern or let non dotnet com client to reuse the pattern to match against different strings, what is the best way? How should I free up the resources held by regex? ...
0
by: jg | last post by:
I need to reuse regex pattern or let non dotnet com client to reuse the pattern to match against different strings, what is the best way? How should I free up the resources held by regex? Right...
4
by: Morgan Cheng | last post by:
In my case, I have to remove any line containing "0.000000" from input string. In below case, it takes about 100 ms for 2k size input string. Regex.Replace(inputString, ".*0\\.000000.*\n", ""); I...
4
by: puzzlecracker | last post by:
if I provide a key of element that doesn't exist in the set, and I call set.erase(nonInSetKey), does standard guarantee that nothing "BAD" will happen, in fact, nothing at all will happen. Does...
4
by: kshw | last post by:
Hi, I'm trying to remove non-stop words from a text file using regular expresions but it is not working. I used something like ('^?or') in order to avoid removing (or) from the mibble of words...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.