473,405 Members | 2,334 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,405 software developers and data experts.

Non Printable Characters using C#

I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.

Many Thanks...
Apr 10 '08 #1
3 17042
Greyhound wrote:
I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.
Use a FileStream to read the existing file and a FileStream for creating the
new file. .Read() from one and .Write() to the other, skipping the unwanted
characters. A BufferedStream may improve performance.

Anything more and I'd be writing the code for you, and that would be bad.

--
J.
Apr 10 '08 #2
On Apr 10, 1:20 pm, Greyhound <rhill...@hotmail.comwrote:
I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.
Just read the text, then remove the appropriate characters using
something like string.Replace. The escape code for FF is "\f" and for
LF it's "\n".

Jon
Apr 10 '08 #3
Greyhound wrote:
I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.
s = Regex.Replace(s, "[\f\n]", "");

or maybe:

s = Regex.Replace(s, "[\u0000-\u001F]", "");

Arne
Apr 10 '08 #4

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

Similar topics

2
by: Jim | last post by:
Hi, Does anyone know of an available java class that will encrypt to cipher text consisting of only printable ascii characters? One of the things I need it for is to encrypt strings that will...
3
by: Pascal | last post by:
Hello, What's the best way to delete or replace no-printable characters in a string. i.e.: "\x08toto\x00titi" -> "tototiti" or " toto titi"
2
by: Daniel Alexandre | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there, I'm using the following method in my program to check whether a message received is printable or not and to strip the non-printable...
2
by: qazmlp | last post by:
How do you check whether an std::string object contains only printable characters ?
8
by: Sam Halliday | last post by:
i want to have a function which can print the printable form (possibly a 2 character string) of a character on UNIX like systems. for example, if i were to pass the ascii value '\3', i would like...
5
by: **Developer** | last post by:
How do I know if the value in a KeyEventArgs is printable? Basicacally, in KeyUp I'd like to know if the character is printable, as opposed to say, a backspace. I suppose I could check...
0
by: ramarajs | last post by:
Hi Team, Can anyone give me the regular expression to search the following set of non printable characters ÑÑNL, &quot; ˜ and many more non printable characters. I have to search these characters...
7
by: active | last post by:
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...
4
by: John K Masters | last post by:
>From what I have read the string module is obsolete and should not be used but I am working on a project that parses printable files created in a DOS program and creates a web page for each file....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.