473,804 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use StreamWriter.Wr iteLine with non-american characters ?


Hi,

For example, if I do :
using System.IO;

using (StreamWriter sw = new StreamWriter("t ext.txt"))
{
sw.WriteLine("c oupé");
}

I end up with a file containing "coupé" instead of "coupé" ...
How can I solve this problem ?

thanks

Feb 20 '07 #1
3 2896
Hi ptek,

The file is correct, but you read it wrong, probably using notepad or similar.
The default StreamReader/StreamWriter uses UTF8 encoding. What you probably want is to use the default encoding

using (StreamWriter sw = new StreamWriter("t ext.txt", false, Encoding.Defaul t))
{
sw.WriteLine("c oupé");
}

PS, encoding is found in the System.Text namespace.
On Tue, 20 Feb 2007 19:49:32 +0100, ptek <pe************ **@gmail.comwro te:
>
Hi,

For example, if I do :
using System.IO;

using (StreamWriter sw = new StreamWriter("t ext.txt"))
{
sw.WriteLine("c oupé");
}

I end up with a file containing "coupé" instead of "coupé" ...
How can I solve this problem ?

thanks



--
Happy coding!
Morten Wennevik [C# MVP]
Feb 20 '07 #2


"ptek" <pe************ **@gmail.comwro te in message
news:11******** **************@ q2g2000cwa.goog legroups.com...

Hi,
You just need to specify an encoding that has the desired characters.
using (StreamWriter sw = new
StreamWriter("t ext.txt",false, Encoding.Defaul t))
{
sw.WriteLine("c oupé");
}

Or

using (StreamWriter sw = new
StreamWriter("t ext.txt",false, Encoding.Unicod e))
{
sw.WriteLine("c oupé");
}

David
Feb 20 '07 #3
On Feb 20, 7:14 pm, "David Browne" <davidbaxterbro wne no potted
m...@hotmail.co mwrote:
"ptek" <pedroduartedr. ..@gmail.comwro te in message

news:11******** **************@ q2g2000cwa.goog legroups.com...

Hi,

You just need to specify an encoding that has the desired characters.

using (StreamWriter sw = new
StreamWriter("t ext.txt",false, Encoding.Defaul t))
{
sw.WriteLine("c oupé");
}

Or

using (StreamWriter sw = new
StreamWriter("t ext.txt",false, Encoding.Unicod e))
{
sw.WriteLine("c oupé");
}

David
Thanks all! It worked like a charm!

Feb 20 '07 #4

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

Similar topics

4
2466
by: Majed | last post by:
Hi , all I'm trying to write unicode to a file for another app (not developed with vs2003) to read it. I used StreamWriter with unicode encoding.but I was surprised that the streamwriter adds FFFE to the start of the file,which stopes the other app from reading it!! any idea how to stope it frome doing that,do I have to use another class #####writer that supports unicode? help me Please! Thanks
9
4598
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the streamwriter, what you have read into a streamReader? and also can someone explain how they work in simple terms -- The Matrix Insurrection
10
4662
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the "Encoding.UTF8" in the constructor like this: StreamWriter writer = new StreamWriter(file, Encoding.UTF8); When I do this the StreamWriter inserts an UTF-8 preamble "" into the
12
11141
by: Nina | last post by:
Hi there, What is the maximum length that one line can hold in a text file using StreamWriter's Write or WriteLine method? If the string is too long for one line to hold, what will Write or WriteLine do? In order me to retrieve data correctly from the text file later, I have to know the right index. For the following code,if str1's length exceeds one line in text file, how can I get str2's index when reading the text file? Is there...
6
10220
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error message: "The process cannot access the file "whatever" because it is being used by another process." I've even tried opening another file using the same streamwriter object before deleting the original file, but it's no use. Something keeps...
3
15739
by: Mads Westen | last post by:
Hi, I'm making some changes to my program, because I need to write with Codepage 850. Before I used FileStream, but I found code to use with StreamWriter instead. My problem is, that I don't get any output when writing with StreamWriter, but only with FileStream. I got StreamWriter to work in another class, where I only have 1 Writeline
2
3544
by: gordon | last post by:
Hi, I am trying to create a reference to an external file to write to using stream writer and a value that is created in a for. Basically the value that a user will create will be the name of the form. The code below show my dilemma. The line "using (StreamWriter sw = new StreamWriter(@"c:\{0}.txt",fmtname)) " does not work as the arguement
1
3992
by: Max Powers | last post by:
Hello, I have a VB.NET code that creates a StreamWriter file first and then it does a series of procedures that write lines for this StreamWriter. When all the procedures are done, the StreamWriter is flushed and closed and all the lines get written to the text. However, if for some reason one of the procedures fails. The StreamWriter doesn't write anything at all and the file ends up empty. Is there a way to save (or actually write)...
7
9789
by: Eran.Yasso | last post by:
Hi, In the MSDN the sample doesn't use the close() method. But I know that in most languages you do need to use the close() method after reading and writing to a file. from MSDN: public static void Main() {
4
12191
by: ºa¤Ö | last post by:
Dear All, Which performance is better? I think 2 is better because only 1 I/O is performed. Am I right? 1. using (StreamWriter sw = File.Append(FileName)) { sw.WriteLine(text1); sw.WriteLine(text2);
0
10571
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
10326
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
10317
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,...
1
7615
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
5520
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...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
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.