473,807 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read a Unicode data saved as ASCII in notepad file as txt ?

How to read a Unicode data saved as ASCII in notepad file as txt ?
I tried using streamReader but it is not showing Unicode data.
eg.
using (StreamReader sr = new StreamReader(te st.txt)
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLi ne(line);
}
Console.Read();
}

Aug 8 '07 #1
3 2487
On Aug 8, 1:06 pm, "Learning.N et" <sanjay.btech2. ..@gmail.comwro te:
How to read a Unicode data saved as ASCII in notepad file as txt ?
Do you mean ANSI rather than ASCII? If so, pass Encoding.Defaul t as a
parameter for your StreamReader constructor.

If it's truly saved as ASCII, you won't have any accented characters
etc, and it should read fine as UTF-8.

Jon

Aug 8 '07 #2

Hi,

I'm not sure I understand the phrase 'unicode data saved as ASCII' - I
guess either the text is ASCII-encoded, or else it is Unicode-encoded?

No matter what, you need to specify an encoding in your code, e.g.:

System.IO.Strea mReader sr = new System.IO.Strea mReader("test.t xt",
System.Text.Enc oding.ASCII)

or

System.IO.Strea mReader sr = new System.IO.Strea mReader("test.t xt",
System.Text.Enc oding.UTF8)

You can also try out different encodings from the intellisense if you
don't know how your file is encoded. If your text still looks funny,
try posting a sample. Hope this is any help.

Morten:)

Aug 8 '07 #3
On Aug 8, 3:34 pm, Maate <ma...@retkomma .dkwrote:
I'm not sure I understand the phrase 'unicode data saved as ASCII' - I
guess either the text is ASCII-encoded, or else it is Unicode-encoded?

No matter what, you need to specify an encoding in your code, e.g.:

System.IO.Strea mReader sr = new System.IO.Strea mReader("test.t xt",
System.Text.Enc oding.ASCII)

or

System.IO.Strea mReader sr = new System.IO.Strea mReader("test.t xt",
System.Text.Enc oding.UTF8)
Well, if it *is* in UTF-8 then you don't need to specify the encoding
- UTF-8 is picked by default by pretty much all the .NET classes (in
this case the docs aren't terribly clear, unfortunately).
You can also try out different encodings from the intellisense if you
don't know how your file is encoded. If your text still looks funny,
try posting a sample. Hope this is any help.
Note that if we do end up seeing a sample, it's probably best to post
the hex version of it - just posting the text will involve other
encoding conversions, which kinda defeats the point...

Jon

Aug 8 '07 #4

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

Similar topics

2
4321
by: Stuart McGraw | last post by:
When I run (Python 2.3.3) this script on a MS Windows 2000 machine: import os print "1st popen..." f = os.popen ("echo " + u"\u0054\u0045\u0053\u0054.txt") print f.read () print "2nd popen..." f = os.popen ("echo " + u"\u5927\u7530\u8061\u7f8e.txt") print f.read ()
0
2604
by: DenoxiS | last post by:
Hi, I've been working on a project that will help me save some time. It basically reads a URL and saves it to disk as an html file. In other words, I just wanted to make the automated version of "Save As -> HTML Only" command on Internet Explorer. I use XMLHTTP component for this task. I created 3 functions: readURL: Reads the given URL using Microsoft.XMLHTTP component and returns the content.
27
5154
by: EU citizen | last post by:
Do web pages have to be created in unicode in order to use UTF-8 encoding? If so, can anyone name a free application which I can use under Windows 98 to create web pages?
4
2656
by: comp.lang.php | last post by:
I have a very simple XML file I created as a sample: I am trying to simply read it using tree-based XML functions in PHP which I know (sorry, don't know or quickly understand DOM though that might be a better option if someone wants to tutor me in it): $fileID = @fopen($_SERVER . '/stuff.xml', 'rb'); //
2
3474
by: Randall Parker | last post by:
Running Python 2.4.2 on Windows in SPE. I have a very small XML file (see below) that is in UTF-8 and saved by Windows Notepad as such. I'm reading it with minidom. My problem is that once I parse the file with minidom and a field from it to another variable as shown with this line: IPAddr = self.SocketSettingsObj.IPAddress I get this error:
1
4066
by: markww | last post by:
Hi, I'm just trying to print the contents of a notepad file I saved with unicode encoding on my win xp machine. I keep getting strange characters printed out though. Why doesn't this work? std::wifstream wifile("C:\\unicode.txt"); if (wifile.is_open()) { wchar_t wszBuffer;
4
4953
by: thebjorn | last post by:
I'm working with a MS SQL Server database created by a program from a fine US company who seems to have gotten run over by the Unicode truck. In their infinite wisdom they've decided to store Unicode data directly in regular varchar fields, utf-8 encoded! (on the bright side, it is properly utf-8 encoded). One of our customers then wants to use a csv file created from a report to import in Excel and is getting an attitude when the text...
4
3326
by: Petr Jakes | last post by:
Hi, I am using Python 2.4.3 on Fedora Core4 and "Eric3" Python IDE .. Below mentioned code works fine in the Eric3 environment. While trying to start it from the command line, it returns: Traceback (most recent call last): File "pokus_1.py", line 5, in ? print str(a) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc1' in
5
4597
by: robson.cozendey.rj | last post by:
Hi, I´m trying desperately to tell the interpreter to put an 'á' in my string, so here is the code snippet: # -*- coding: utf-8 -*- filename = u"Ataris Aquáticos #2.txt" f = open(filename, 'w') Then I save it with Windows Notepad, in the UTF-8 format. So:
0
9599
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
10624
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...
0
10371
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
10374
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
9193
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
6877
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
5546
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...
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
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.