Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect non-printable characters in .NET?

Tags:

c#

.net

vb.net

I'm just wondering if there is a method in .NET 2.0 that checks whether a character is printable or not – something like isprint(int) from standard C.

I found Char.IsControl(Char).

Could that be used for this purpose?

like image 441
Baldewin Avatar asked Jul 15 '10 07:07

Baldewin


People also ask

How do I check if all characters in a string are printable?

The isprintable() method returns “True” if all characters in the string are printable or the string is empty, Otherwise, It returns “False”. This function is used to check if the argument contains any printable characters such as: Digits ( 0123456789 ) Uppercase letters ( ABCDEFGHIJKLMNOPQRSTUVWXYZ )

How do I find non-printable characters in a text file?

Option #1 - Show All Characters Then, go to the menu and select View->Show Symbol->Show All Characters . All characters will become visible, but you will have to scroll through the whole file to see which character needs to be removed.


1 Answers

You might want to use Char.IsControl(Char). That is what I'm using. You definitely do not want to use the <0x20 method because any non-latin character and most non-english characters will be above 127.

like image 74
Cranston Avatar answered Sep 22 '22 23:09

Cranston