473,396 Members | 1,804 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.

ASCII, StreamWriter and swedish letters

MA
Hi all!

I have a major problem. I need to write an textfile with 1 b per letter. But
it should be able to handle swedish letters to (åäö).
Is it possible to use 8 b ASCII for this?
This file is used by an sms application and cannot be in another format.

/Marre
Nov 16 '05 #1
12 15391
MA <ne**@supremelink.se> wrote:
I have a major problem. I need to write an textfile with 1 b per letter. But
it should be able to handle swedish letters to (åäö).
Is it possible to use 8 b ASCII for this?
There's no such thing as "8 bit ASCII" (assuming that's what you meant
by "b").
This file is used by an sms application and cannot be in another
format.


You need to find out *exactly* what encoding will be used. There are
various 8 bit character sets which are compatible with ASCII in the
range 0-127, but which are incompatible with each other above 127. If
you can find out which of those your app needs to output, it should be
easy to find the appropriate Encoding to give to your StreamWriter.

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

I believe Swedish uses the standard European characterset ISO-8859-1, or you could use ISO-8859-15 which is the nordic set (no å and æ in 8859-1, so I would recomment the latter)

System.IO.StreamWriter sw = new System.IO.StreamWriter(path);
sw.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-15");

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
You could also use cp1252, which supports Swedish well.

Or even better Unicode, which supports everything.
--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies
Windows International Division

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opseqzkntdklbvpo@server72...
Hi Marre,

I believe Swedish uses the standard European characterset ISO-8859-1, or you could use ISO-8859-15 which is the nordic set (no å and æ in 8859-1, so
I would recomment the latter)
System.IO.StreamWriter sw = new System.IO.StreamWriter(path);
sw.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-15");

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #4
On Wed, 22 Sep 2004 07:24:27 -0700, Michael (michka) Kaplan [MS] <mi*****@online.microsoft.com> wrote:
You could also use cp1252, which supports Swedish well.

Or even better Unicode, which supports everything.


Well, Unicode wouldn't be 8-bit, now would it :P

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #5
UTF-8 works with bytes....
--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies
Windows International Division

This posting is provided "AS IS" with
no warranties, and confers no rights.

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opseqfx7h3klbvpo@stone...
On Wed, 22 Sep 2004 07:24:27 -0700, Michael (michka) Kaplan [MS] <mi*****@online.microsoft.com> wrote:
You could also use cp1252, which supports Swedish well.

Or even better Unicode, which supports everything.


Well, Unicode wouldn't be 8-bit, now would it :P

--
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #6
Michael (michka) Kaplan [MS] <mi*****@online.microsoft.com> wrote:
UTF-8 works with bytes....


Well, I wouldn't say it's an "8-bit encoding" in the normal sense of
the phrase...

Not every character in the set (in fact, very few!) can be represented
as a single byte.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote...
Not every character in the set (in fact, very few!) can be represented
as a single byte.


Yes -- but Unicode covers a lot of ground. Attempts to do less lead to
corruption of text in the "lesser" code page, and I am reasonably certasin
that such corruption is never a good thing....

:-)

--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies
Windows International Division

This posting is provided "AS IS" with
no warranties, and confers no rights.
Nov 16 '05 #8
Michael (michka) Kaplan [MS] <mi*****@online.microsoft.com> wrote:
Not every character in the set (in fact, very few!) can be represented
as a single byte.


Yes -- but Unicode covers a lot of ground. Attempts to do less lead to
corruption of text in the "lesser" code page, and I am reasonably certasin
that such corruption is never a good thing....


That's pretty much irrelevant when the encoding is fixed to start with
though, as the OP says it is. The best you can do is detect that you're
trying to write a character which isn't in the target character set,
and either throw an exception or write something else (eg '?').

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

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
MA <ne**@supremelink.se> wrote:
I have a major problem. I need to write an textfile with 1 b per letter.
But
it should be able to handle swedish letters to (åäö).
Is it possible to use 8 b ASCII for this?
There's no such thing as "8 bit ASCII" (assuming that's what you meant
by "b").
This file is used by an sms application and cannot be in another
format.


You need to find out *exactly* what encoding will be used. There are
various 8 bit character sets which are compatible with ASCII in the
range 0-127, but which are incompatible with each other above 127. If
you can find out which of those your app needs to output, it should be
easy to find the appropriate Encoding to give to your StreamWriter.

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

Ok. Is it ASCII-8 then?

Well, I solved it by using this code:

char[] test = mailContent.ToCharArray();

System.Text.Encoding enc = System.Text.Encoding.GetEncoding("437");

System.Text.Encoder ence = enc.GetEncoder();

FileStream fsWriter = new FileStream(filePath + fileName,
System.IO.FileMode.Create);

byte[] bytes = new Byte[ence.GetByteCount(test,0, test.Length, true)];

ence.GetBytes(test, 0, test.Length, bytes, 0, true);

fsWriter.Write(bytes, 0, bytes.Length);

/Marre
Nov 16 '05 #10
[Please fix your newsreader to quote properly, btw - it's a pain to
reply when you follow-up in the way you have, especially including the
sig separator from my post]

MA <ne**@supremelink.se> wrote:
Ok. Is it ASCII-8 then?
Is what "ASCII-8", exactly? Can't say I've heard of that before.
Well, I solved it by using this code:

char[] test = mailContent.ToCharArray();

System.Text.Encoding enc = System.Text.Encoding.GetEncoding("437");

System.Text.Encoder ence = enc.GetEncoder();

FileStream fsWriter = new FileStream(filePath + fileName,
System.IO.FileMode.Create);

byte[] bytes = new Byte[ence.GetByteCount(test,0, test.Length, true)];

ence.GetBytes(test, 0, test.Length, bytes, 0, true);

fsWriter.Write(bytes, 0, bytes.Length);


Just using StreamReader with an encoding of Encoding.GetEncoding("437")
would be rather simpler. However, are you *really* sure it's code page
437? If you've got the wrong code page, you'll write out the wrong
characters sooner or later.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #11
MA
> Is what "ASCII-8", exactly? Can't say I've heard of that before.
Well, as you might have noticed, I´m really a newbie here :) I looked at
this link:
http://homepage.cs.uri.edu/faculty/w...pleteASCII.htm

Just using StreamReader with an encoding of Encoding.GetEncoding("437")
would be rather simpler. However, are you *really* sure it's code page
437? If you've got the wrong code page, you'll write out the wrong
characters sooner or later.

Yes. According to those who have developed the app I´m 'talking' with, it´s
437.
It´s not that important if some character get wrong, but if it happends, I
will probably return to this newsgroup :)

Sorry for my quote-problem. Never thougt of that before.

/Marre
Nov 16 '05 #12
MA <ne**@supremelink.se> wrote:
Is what "ASCII-8", exactly? Can't say I've heard of that before. Well, as you might have noticed, I´m really a newbie here :) I looked at
this link:
http://homepage.cs.uri.edu/faculty/w...pleteASCII.htm


Any page which claims ASCII has characters over 127 shouldn't be
trusted, I'm afraid...
Just using StreamReader with an encoding of Encoding.GetEncoding("437")
would be rather simpler. However, are you *really* sure it's code page
437? If you've got the wrong code page, you'll write out the wrong
characters sooner or later.

Yes. According to those who have developed the app I´m 'talking' with, it´s
437.


Good. It's always nice when you don't have to guess :)
It´s not that important if some character get wrong, but if it happends, I
will probably return to this newsgroup :)
Righto.
Sorry for my quote-problem. Never thougt of that before.


No problem - thanks for fixing it.

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

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

Similar topics

12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
9
by: Anna | last post by:
Hi, I use the Swedish letters å,ä,ö in my HTML code and it works perfectly in IE, but not in Netscape and Mozilla browsers. Does anyone know how to fix it? I use &aring for å, &auml for ä and...
37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
1
by: R.L. | last post by:
See the code below, var 'content ' is suppose to be "Hello!", not "". Who knows why? Thanks ---------------------------------------- string text = "hello!"; MemoryStream stream = new...
5
by: Gidi | last post by:
Hi, 1. I have a string that i want to write into a file. the string is build from few textboxs (str=text1+text2...), how can i write the string to the file in ASCII format? 2. I need my...
61
by: Christoph Zwerschke | last post by:
On the page http://wiki.python.org/moin/Python3%2e0Suggestions I noticed an interesting suggestion: "These operators ≤ ≥ ≠ should be added to the language having the following meaning: ...
7
by: Joris De Groote | last post by:
Hi, I have a 1 dimensional table byte with a number af characters in ASCII code. How do I convert those ASCII codes to real letters? Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.