473,591 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get StreamReader to properly read unusual characters?

Hi, I'm using a StreamReader (readLine()) to read text from a file, but some
lines in the file I'm reading have odd characters, such as the Euro symbol,
etc. I find that no matter what encoding I use with the StreamReader, these
characters either get entirely ignored, replaced with a "?", or replaced by
some other character. Is there anything I can do to make this work, or
should I use something like BinaryReader?
Thanks.
Nov 15 '05 #1
2 3114
Alien,
When you create the StreamReader be certain that you use the correct
Encoding class for your file.

http://msdn.microsoft.com/library/de...ctorTopic4.asp

http://msdn.microsoft.com/library/de...ctorTopic6.asp

For information on Encoding, Unicode & character sets see:
http://www.joelonsoftware.com/articles/Unicode.html
&
http://www.yoda.arachsys.com/csharp/unicode.html

Hope this helps
Jay

"alien" <al***@sympatic o.ca> wrote in message
news:d9******** **********@news 20.bellglobal.c om...
Hi, I'm using a StreamReader (readLine()) to read text from a file, but some lines in the file I'm reading have odd characters, such as the Euro symbol, etc. I find that no matter what encoding I use with the StreamReader, these characters either get entirely ignored, replaced with a "?", or replaced by some other character. Is there anything I can do to make this work, or
should I use something like BinaryReader?
Thanks.

Nov 15 '05 #2
Thanks, that helped, I've got it working now.

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Alien,
When you create the StreamReader be certain that you use the correct
Encoding class for your file.

http://msdn.microsoft.com/library/de...ctorTopic4.asp
http://msdn.microsoft.com/library/de...ctorTopic6.asp
For information on Encoding, Unicode & character sets see:
http://www.joelonsoftware.com/articles/Unicode.html
&
http://www.yoda.arachsys.com/csharp/unicode.html

Hope this helps
Jay

"alien" <al***@sympatic o.ca> wrote in message
news:d9******** **********@news 20.bellglobal.c om...
Hi, I'm using a StreamReader (readLine()) to read text from a file, but

some
lines in the file I'm reading have odd characters, such as the Euro

symbol,
etc. I find that no matter what encoding I use with the StreamReader,

these
characters either get entirely ignored, replaced with a "?", or replaced

by
some other character. Is there anything I can do to make this work, or
should I use something like BinaryReader?
Thanks.


Nov 15 '05 #3

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

Similar topics

4
3095
by: G.Esmeijer | last post by:
Friends, Want to read a textfile with characters that go above 7F ( ascii > 128) and put the results line by line in a string to process it further I used a streamreader to do so but the readline() methods in someway skipps the characters > 127 . I used the binary reader as well, same result. string regel; StreamReader sr = new StreamReader ( ImportFile, System.Yext.Unicode.UTF8);
6
4182
by: Jesper | last post by:
Hi, Im using a code snippet that reads a text file from disc and processes it using stream = new StreamReader(filename); Is it possible to assign a String instead of a file as the source of the stream, and if yes, how?
4
4537
by: Marcus O via DotNetMonster.com | last post by:
Hello, I am fairly new to vb.net and I have a problem when reading from text file. The file contains characters not found in English (e.g. ?, ?, ?). When I am doing a ReadLine those characters are skipped by vb.net. Does anyone know what to do to fix my problem? /m -- Message posted via http://www.dotnetmonster.com
3
5115
by: Chip | last post by:
There is surprisingly little information on the various encoding options for reading a text file. I have what seems to be a very basic issue: I'm reading a text file that includes Spanish characters such as "ñ". When I read the file into a string, that character is missing. Encoding seems to be the culprit. File writers SHOULD begin a file with the BOM (Byte Order Mark) to let us know what encoding to read the file with, but most software...
2
2731
by: rVo | last post by:
In a VB.Net application I create a new streamreader and use it's ReadToEnd function to read the contents of a htmlfile. Inside the file there are some signs like öéèêë..., these signs are not present in the stream that has been read by the ReadToEnd function though. This problem occured in a program that has been running succesfully for about a yeatr already. Could this have been caused by recent patches or an upgrade of the dot net...
7
8197
by: asvini | last post by:
Hi I want to read a file which has data and null characters in between... But my program terminates on encountering NULL characters...is there any other way to read the whole file with the NULL characters.. thanks in advance... regards asvini
7
6794
by: Sushmita | last post by:
Hi All I am trying to read russian characters from xml,while doing so,i have taken care of UTF-8,but still few letters come in form of question marks and square blocks. Please can anyone help me out with this.... Thanks..
2
4020
borisding
by: borisding | last post by:
Hi there, I'm using Jmail for sending email with some attachments. Basically, I will need to send out email with the contents in unicode characters such as Simplified Chinese, Japanese etc. I have tried out and all characters are displayed well, if ONLY for me to send it to webmail such as Yahoo!/Gmail. However, I was unable to read the characters when sending to my own company email address, even on the company's webmail. All characters...
1
3161
by: maker2254 | last post by:
I have a text file which I attached in this post.I read this file using StreamReader in c# and insert into SQL. When I try to insert the data,I get error.I was trying to find the problem for that i tried removing the text word by word from the text file and trying the code again.Finally I found the problematic part , removed it and successfully inserted into SQL . When I copy the text and paste into notepad ,there is nothing I could observe. ....
0
7934
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
7870
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
8236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7992
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
8225
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...
0
6639
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3850
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
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.