How can I convert high ASCII to low ASCII

F

Friso Wiskerke

Hi all,

I'm creating a fixed length textfile with data which is sent out to a
third-party which in turn reads the file and processes it. Some of the
characters are not part of the lower ASCII table. This causes problems
because an È (&HC4) in the textfile is converted into 2 bytes on the
receiving end which then in turn shifts the remaining data on the line one
byte to the right... and in a fixed length textfile that's a disaster

Is there a way to convert accented characters like: È (&HC4), É (&HC5), Ê
(&HC6) to it's non-accented counterpart: E (&H45)?
Same goes for accented A's and O's....

TIA,
Friso Wiskerke
 
C

Cor Ligthert

Friso,

This is because ASCII is 7 bits, (although AscW) is too complete unicode.

Probably are you searching for something as is in this sample.

\\\
Public Shared Sub main()
If File.Exists("C:\Test2\Text.txt") Then _
File.Delete("C:\Test2\StringText.txt")
Dim stw As New StreamWriter("C:\Test2\StringText.txt")
stw.WriteLine("123âäfabc")
stw.Close()
Dim Str As New StreamReader("C:\Test2\StringText.txt")
Dim arrInput As Byte() = _
System.Text.Encoding.GetEncoding(437).GetBytes(Str.ReadToEnd)
Str.Close()
End Sub
///

437 covers the complete used Dutch characterset however sometimes was as
well used 850, windows in Holland is 1252 and that table is more complete.

I hope this helps?

Cor
 
F

Friso Wiskerke

Thanks,

however I don't have control over the application which reads and processes
the file. The third-party who does this is using an app. which is quite a
few years old and altering/rebuilding is not an option from their part.

So it's up to me to deliver the data so that they can process it and that
means converting those accented characters.

Cheers,
Friso
 
H

Herfried K. Wagner [MVP]

Friso Wiskerke said:
I'm creating a fixed length textfile with data which is sent out to a
third-party which in turn reads the file and processes it. Some of the
characters are not part of the lower ASCII table. This causes problems
because an È (&HC4) in the textfile is converted into 2 bytes on the
receiving end which then in turn shifts the remaining data on the line one
byte to the right... and in a fixed length textfile that's a disaster

ASCII doesn't contain these characters. Do you know what encoding was used
to encode the text file?
 
F

Friso Wiskerke

Herfried,,

The file which I'm creating is UTF8 encoded. So an È is written as one byte:
&H4C. The problem is that I have absolutely no idea how the file is being
imported on the receiving end. It's also not an option to change the
receiving app. (unfortunately).

Is looks like that the È is being split up into 2 bytes which then results
in the fact that the remaining data on the line is shifted one byte to the
right.

Cheers,
Friso
 
J

Jay B. Harlow [MVP - Outlook]

Friso,
In addition to the other comments:
Is there a way to convert accented characters like: È (&HC4), É (&HC5),
Ê
(&HC6) to it's non-accented counterpart: E (&H45)?
Same goes for accented A's and O's....
It sounds like you know you have accented characters, but you want to write
the file explicitly in ASCII.


I would expect you could use something like:
Dim writer As New StreamWriter("Ascii.txt", False, Encoding.ASCII)
writer.WriteLine("A=À Á à á")
writer.WriteLine("E=È É è é")
writer.WriteLine("I=Ì Í ì í")
writer.WriteLine("O=Ò Ó ò ó")
writer.WriteLine("U=Ù Ú ù ú")
writer.Close()


Unfortunately the ASCII encoding object is converting the accented
characters to question marks, which is partially understandable. I was
expecting/hoping using the ASCII encoding object would convert an accented È
to a normal E...

I'm not seeing any thing obvious on the Encoding class, Have you tried
asking in the microsoft.public.dotnet.internationalization?

Note: The default for StreamWriter is UTF8, which is where the 2 bytes are
coming from, instead of ASCII or UTF8, I normally use Encoding.Default,
which will use the encoding set in the Regional settings of Windows Control
Panel. This will get ride of the 2 byte characters, however you will still
have an extended character (ANSI, not ASCII).

Dim writer As New StreamWriter("Ascii.txt", False, Encoding.Default)

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top