French charactor

G

Guest

Hello,

I want to read a text file which contains French charactor, then modify some of the
sentence, save it as a new text file.
But I found the new text file lost all the French charactors.
Anybody can help me?

Thanks,

Yongjian

My code:
StreamReader sr = new StreamReader(stSource,Encoding.UTF8);
StreamWriter sw = new StreamWriter(stDestination,false, Encoding.UTF8);

while ((stLine = sr.ReadLine())!=null)
{
// add something to the stLine, then write it to a new file

sw.WriteLine(stLine);
}
sr.Close();
sw.Close();
 
J

Jon Skeet [C# MVP]

Yongjian said:
I want to read a text file which contains French charactor, then modify some of the
sentence, save it as a new text file.
But I found the new text file lost all the French charactors.
Anybody can help me?

Chances are you're just using the wrong encoding. Do you know for sure
what encoding your original file is in?
 
G

Guest

Thank you for yor replying.

I don't know the what encoding the original file is. I believe it should use default encoding. It looks like(it contains "é"):

Plan name: Régime de retraite des employés rémunérés à l'heure de Les Poudres Métalliques du Québec Ltée.
Province of registration: QC
Registration number: 25803
Service end date: 31 May 2003
 
J

Jon Skeet [C# MVP]

YJ said:
I don't know the what encoding the original file is. I believe it
should use default encoding. It looks like(it contains "?"):

Well, you can try using Encoding.Default (which isn't the one used by
default, confusingly enough) but to be honest if you don't know the
encoding, there's no guarantee you'll get it right.
 
G

Guest

Hi ,

I used "Request.Params["sName"]" on the Page_Load event.

I could not read the French like "é" If the sName has French, ie. if I pass the url like "webFom1?sName='abé'", then the Request.Params["sName"]"will equal to "ab", the "é" get choped.,
What should I do?

I used System.text; and set Request.contentEncoding =encoding.default or Request.contentEncoding =encoding.utf-7, none of them works.

Thanks, Jasmine
 
G

Guest

Hi ,

I used "Request.Params["sName"]" on the Page_Load event.

I could not read the French like "é" If the sName has French, ie. if I pass the url like "webFom1?sName='abé'", then the Request.Params["sName"]"will equal to "ab", the "é" get choped.,
What should I do?

I used System.text; and set Request.contentEncoding =encoding.default or Request.contentEncoding =encoding.utf-7, none of them works.

Thanks, Jasmine
 
J

Jon Skeet [C# MVP]

Jasmine said:
I used "Request.Params["sName"]" on the Page_Load event.

I could not read the French like "?" If the sName has French, ie. if
I pass the url like "webFom1?sName='ab?'", then the
Request.Params["sName"]"will equal to "ab", the "?" get choped.,
What should I do?

You should avoid passing things in the URL, to start with. URL content
encoding is a murky business, from what I remember. If you make the
request a POST rather than a GET, and put the data in the content
rather than the URL, you're more likely to get something useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top