473,549 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ 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 15416
MA <ne**@supremeli nk.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.co m>
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.Strea mWriter sw = new System.IO.Strea mWriter(path);
sw.Encoding = System.Text.Enc oding.GetEncodi ng("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:opseqzkntd klbvpo@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.Strea mWriter sw = new System.IO.Strea mWriter(path);
sw.Encoding = System.Text.Enc oding.GetEncodi ng("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:opseqfx7h3 klbvpo@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.co m>
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.co m> 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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
MA <ne**@supremeli nk.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.co m>
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.ToC harArray();

System.Text.Enc oding enc = System.Text.Enc oding.GetEncodi ng("437");

System.Text.Enc oder ence = enc.GetEncoder( );

FileStream fsWriter = new FileStream(file Path + fileName,
System.IO.FileM ode.Create);

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

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

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

/Marre
Nov 16 '05 #10

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

Similar topics

12
8197
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 not - be able to use non-ASCII characters in strings and in Tk GUI button labels and GUI window titles and in raw_input data without Python returning...
9
5608
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 &ouml for ö. Thanx
37
10125
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 accidentally entered are properly represented when the document is served. My programming language allows me to get the ascii value for any individual...
1
4663
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 MemoryStream(); StreamWriter streamWriter = new StreamWriter(stream, Encoding.ASCII); streamWriter.Write(text);
5
3605
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 string will be 120 char length, and incase the string is less then 120 chars, i need to fill it with spaces till it will be 120 chars length, is there a...
61
4890
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: <= >= != this should improve readibility (and make language more accessible to beginners).
7
16164
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
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
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. ...
0
7957
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...
0
7809
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6043
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
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...
0
5088
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
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...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.