473,322 Members | 1,523 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,322 software developers and data experts.

is unicode support in c# a fake?

Hi!
I don't know why, but I want to read a file, change some of the content, and
want to write this new content in another file. The problem is, that it
contains unicode text.

My code is:

System.IO.StreamReader reader =
new System.IO.StreamReader(this.openFileDialog1.FileNa me,Encoding.Unicode);

string new_filename = this.openFileDialog1.FileName.Replace(".txt",
"(###).txt");

System.IO.StreamWriter writer =
new System.IO.StreamWriter(new_filename, true, Encoding.Unicode);

string FILE = reader.ReadToEnd();
writer.Write(FILE);

writer.Close();
reader.Close();

I have not altered the content at all. This is the whole code from my
function private void openFileDialog1_FileOk(object sender, CancelEventArgs
e).

I hope you can help me. Please?
Aug 22 '07 #1
3 3879
Alexander <Al*******@discussions.microsoft.comwrote:
I don't know why, but I want to read a file, change some of the content, and
want to write this new content in another file. The problem is, that it
contains unicode text.
And that's fine, but you need to use the right encodings.
My code is:

System.IO.StreamReader reader =
new System.IO.StreamReader(this.openFileDialog1.FileNa me,Encoding.Unicode);
Is your text genuinely encoded with Unicode? Just because it contains
Unicode characters doesn't mean it's *encoded* as Unicode.

Where did you get your file from in the first place?

(Oh, and what happens when you run your code? You never specified.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 22 '07 #2
What's the problem? Are you saying that the file you write doesn't contain
Unicode?
"Alexander" <Al*******@discussions.microsoft.comwrote in message
news:00**********************************@microsof t.com...
Hi!
I don't know why, but I want to read a file, change some of the content,
and
want to write this new content in another file. The problem is, that it
contains unicode text.

My code is:

System.IO.StreamReader reader =
new
System.IO.StreamReader(this.openFileDialog1.FileNa me,Encoding.Unicode);

string new_filename = this.openFileDialog1.FileName.Replace(".txt",
"(###).txt");

System.IO.StreamWriter writer =
new System.IO.StreamWriter(new_filename, true, Encoding.Unicode);

string FILE = reader.ReadToEnd();
writer.Write(FILE);

writer.Close();
reader.Close();

I have not altered the content at all. This is the whole code from my
function private void openFileDialog1_FileOk(object sender,
CancelEventArgs
e).

I hope you can help me. Please?
Aug 22 '07 #3
Alexander wrote:
Hi!
I don't know why, but I want to read a file, change some of the content, and
want to write this new content in another file. The problem is, that it
contains unicode text.
How is that a problem?
My code is:

System.IO.StreamReader reader =
new System.IO.StreamReader(this.openFileDialog1.FileNa me,Encoding.Unicode);
The Encoding.Unicode gets an encoding for UTF-16. Text files are usually
saved as UTF-8, not UTF-16.

What encoding was used to save the text? UTF-7? UTF-8? UTF-16? UTF-32?
string new_filename = this.openFileDialog1.FileName.Replace(".txt",
"(###).txt");

System.IO.StreamWriter writer =
new System.IO.StreamWriter(new_filename, true, Encoding.Unicode);

string FILE = reader.ReadToEnd();
writer.Write(FILE);

writer.Close();
reader.Close();

I have not altered the content at all. This is the whole code from my
function private void openFileDialog1_FileOk(object sender, CancelEventArgs
e).

I hope you can help me. Please?
With what? It's hard to help you if you don't even tell what the problem
is...

If the problem is that the file is not read and written correctly, just
specify the correct encoding.

--
Göran Andersson
_____
http://www.guffa.com
Aug 22 '07 #4

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

Similar topics

8
by: sebastien.hugues | last post by:
Hi I would like to retrieve the application data directory path of the logged user on windows XP. To achieve this goal i use the environment variable APPDATA. The logged user has this name:...
48
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at...
32
by: Wolfgang Draxinger | last post by:
I understand that it is perfectly possible to store UTF-8 strings in a std::string, however doing so can cause some implicaions. E.g. you can't count the amount of characters by length() | size()....
5
by: Morten Wennevik | last post by:
I made a program than can send text to Putty (A telnet/ssh client) http://www.chiark.greenend.org.uk/~sgtatham/putty/ And I discovered that Unicode characters doesn't reach it I'm using...
3
by: Andres A. | last post by:
I have bunch of unicode characters stored as Decimal is there a easy way of displaying unicode from Decimal numbers or do i have to convert the decimal to hex then display the hex? i ran into a...
13
by: Tomás | last post by:
Let's start off with: class Nation { public: virtual const char* GetName() const = 0; } class Norway : public Nation { public: virtual const char* GetName() const
13
by: Kelvin Moss | last post by:
Hi all, How could one write an strstr function to work with unicode characters? Are there existing implementations/solutions/api for doing so? Any pointers would be appreciated. Thanks ..
17
by: Adam Olsen | last post by:
As was seen in another thread, there's a great deal of confusion with regard to surrogates. Most programmers assume Python's unicode type exposes only complete characters. Even CPython's own...
29
by: Ioannis Vranos | last post by:
Hi, I am currently learning QT, a portable C++ framework which comes with both a commercial and GPL license, and which provides conversion operations to its various types to/from standard C++...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.