Converting to ASCII8

  • Thread starter Thread starter Klaus Jensen
  • Start date Start date
K

Klaus Jensen

Hi!

In this code...:

Dim oAsciiStreamWriter As New StreamWriter("C:\Temp\TestAscii.txt", False,
System.Text.ASCIIEncoding.ASCII)
oAsciiStreamWriter.WriteLine("Test of danish chars - ÆØÅæøå")
oAsciiStreamWriter.Close()
oAsciiStreamWriter = Nothing

....I convert the string "Test of danish chars - ÆØÅæøå" to ASCII7... Is
there an easy way to convert to ASCII8, so I can keep the stupid Danish
chars?

Thanks in advance

Klaus Jensen
 
Klaus Jensen said:
Hi!

In this code...:

Dim oAsciiStreamWriter As New StreamWriter("C:\Temp\TestAscii.txt",
False, System.Text.ASCIIEncoding.ASCII)
oAsciiStreamWriter.WriteLine("Test of danish chars - ÆØÅæøå")
oAsciiStreamWriter.Close()
oAsciiStreamWriter = Nothing

...I convert the string "Test of danish chars - ÆØÅæøå" to ASCII7...
Is there an easy way to convert to ASCII8, so I can keep the stupid
Danish chars?


ASCII = 7 bits

Maybe you are looking for ANSI encoding? Try System.Text.Encoding.Default.
 
Hi Klaus,

If nobody gives you an answer for a direct convert, I would just do it like
this,
Dim Normal As New System.Text.StringBuilder("ÆØÅæøå")
Normal = Normal.Replace("Æ", "AE")
Normal = Normal.Replace("Ø"c, "O"c)
Normal = Normal.Replace("Å"c, "A"c)
Normal = Normal.Replace("æ"c, "A"c)
Normal = Normal.Replace("ø"c, "o"c)
Normal = Normal.Replace("å"c, "a"c)
Dim normalstri As String = Normal.ToString
MessageBox.Show(normalstri)

The strings are probably small and this is I think fast enough, the only
thing is to find the right characters. (and when you have a real character
replace use than the ""c (character) that is very fast).

Cor
 
Hello, Klaus:

It depends on what you are doing with your TestAscii.txt file.
If you want to open it with an ANSI application (all Windows applications will recognize it), you can use system.text.encoding.default, as Armin said.
If you are sending it to a device (such a printer) or a MS-DOS system that uses codepages, you can use:
Dim oAsciiStreamWriter As New StreamWriter("C:\Temp\TestAscii.txt", False, New System.Text.Encoding(850))

Where 850 is the default code page for the Danish versions of DOS.

Regards.


"Klaus Jensen" <CurseThemNastySpammers!> escribió en el mensaje | Hi!
|
| In this code...:
|
| Dim oAsciiStreamWriter As New StreamWriter("C:\Temp\TestAscii.txt", False,
| System.Text.ASCIIEncoding.ASCII)
| oAsciiStreamWriter.WriteLine("Test of danish chars - ÆØÅæøå")
| oAsciiStreamWriter.Close()
| oAsciiStreamWriter = Nothing
|
| ...I convert the string "Test of danish chars - ÆØÅæøå" to ASCII7... Is
| there an easy way to convert to ASCII8, so I can keep the stupid Danish
| chars?
|
| Thanks in advance
|
| Klaus Jensen
|
|
|
 
Back
Top