473,750 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17101
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...@hotma il.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
5360
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 then be used as filenames. TIA, Jim
3
2492
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
5475
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 characters: CheckPrintable(self,message): printablemessage = ""
2
8872
by: qazmlp | last post by:
How do you check whether an std::string object contains only printable characters ?
8
1965
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 it printed "^C". there is a file called charset.c in the distribution of less ftp://ftp.gnu.org/gnu/less/less-382.tar.gz] which achieves this, but it is quite long winded and i do not wish to have to copy all the relevant code, as it is longer...
5
3292
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 KeyValue against some integers which I could get from an ASCII table. Isn't there a better way?
0
3105
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 and remove the same from the file. I need the regular expression to find the combination of above said characters. Any inputs on the same would be appreciated. Thanks in advance. Thank you, Ramaraj. S
7
34639
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 better. Like a \something that does it all? Return Regex.Replace(oStr, "", "").Trim
4
2521
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. I am using the string.printable constant to determine which characters should be kept; the files contain many print control codes. There seems to be nothing like this in the string methods. isalnum() seems the nearest but gives false for '+' '!'...
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9397
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9344
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9257
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6810
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.