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

Problem with encoding....

Hi all. I have a c# app that sometimes writes to a textfile. Sometimes
the text contains the swedish letters åäö. In the app these letters look
ok, but when StreamWriter has written them to the file they look like
shit. Some encoding mismatch is happening here I suspect, but I cant
find it.

I run English version of XP with swedish regional settings everywhere I
can find them :-).

Any hints would be much appreciated. Thanx

/ZW
Nov 16 '05 #1
3 2696
Hi, ZoombyWoof

Stream uses default Encodings and you might need to specify directly which
one to use

e.g. for encoding bytes from file properly to string I use constructs like
System.Text.Encoding.GetEncoding(myEncodingNumber) .GetString(data)

You might need to use similar approach when preparing data for StreamWriter

HTH
Alex

"ZoombyWoof" <zo**************@thishotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
Hi all. I have a c# app that sometimes writes to a textfile. Sometimes
the text contains the swedish letters åäö. In the app these letters look
ok, but when StreamWriter has written them to the file they look like
shit. Some encoding mismatch is happening here I suspect, but I cant
find it.

I run English version of XP with swedish regional settings everywhere I
can find them :-).

Any hints would be much appreciated. Thanx

/ZW

Nov 16 '05 #2
Hi. Thanx :-) I had to specify the encoding in the call to the
StreamWriter constructor and this one worked:
sw = new StreamWriter( fullname, false, System.Text.Encoding.Unicode );

The file gets twice the size as before, but it works.

Thanx again

/ZW

AlexS wrote:
Hi, ZoombyWoof

Stream uses default Encodings and you might need to specify directly which
one to use

e.g. for encoding bytes from file properly to string I use constructs like
System.Text.Encoding.GetEncoding(myEncodingNumber) .GetString(data)

You might need to use similar approach when preparing data for StreamWriter

HTH
Alex

"ZoombyWoof" <zo**************@thishotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
Hi all. I have a c# app that sometimes writes to a textfile. Sometimes
the text contains the swedish letters åäö. In the app these letters look
ok, but when StreamWriter has written them to the file they look like
shit. Some encoding mismatch is happening here I suspect, but I cant
find it.

I run English version of XP with swedish regional settings everywhere I
can find them :-).

Any hints would be much appreciated. Thanx

/ZW


Nov 16 '05 #3
ZoombyWoof <zo**************@thishotmail.com> wrote:
Hi. Thanx :-) I had to specify the encoding in the call to the
StreamWriter constructor and this one worked:
sw = new StreamWriter( fullname, false, System.Text.Encoding.Unicode );

The file gets twice the size as before, but it works.


If you're able to specify the encoding for both writing and reading,
I'd recommend Encoding.UTF8, which is very efficient for mainly-ASCII
files and can still represent all Unicode characters.

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

6
by: Club-B42 | last post by:
i've compiled my programm using command "python setup.py py2exe >1" python script works fine, but .exe version fails with =====================================================================...
3
by: Tjerk Wolterink | last post by:
Helo i'v an xml file like this: <bestand> <id>8</id> <beschrijving type="string"><!]></beschrijving> <file type="file" mime-type-image="/xcm/mime_types/movie.gif"><!]></file> </bestand>
8
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the...
5
by: James Wong | last post by:
Dear all, I've a web service function and it contains a parameter in System.Text.Encoding. I found that the data type of this parameter in caller application becomes MyWebSvcName.Encoding...
2
by: Ali | last post by:
I am having problem compiling schema contained in WSDL file when analyzing schema types contained in it (for example http://www.ebout.net/net/GoogleSearch.wsdl). Following code demonstrates my...
4
by: Cott Lang | last post by:
ERROR: could not convert UTF-8 character 0x00ef to ISO8859-1 Running 7.4.5, I frequently get this error, and ONLY on this particular character despite seeing quite a bit of 8 bit. I don't really...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects"...
0
by: helldiversafe-news | last post by:
Hi all, I will use a apache soap service with an .net c# client and have a problem with an complex array: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope...
12
by: Punkis | last post by:
Hi all, I have a problem with my php and mysql project. I use an auctions software, named phpauction for my project. I import into my database with utf8 encodingm and I can see the greek...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.