473,484 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 15397
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
8183
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
5602
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
10115
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
4655
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
3600
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
4857
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
16140
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
7082
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
7105
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
7144
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...
1
4845
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...
0
4529
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3046
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...
0
1359
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 ...
1
592
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
235
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...

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.