473,320 Members | 2,164 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,320 software developers and data experts.

ASCII / ANSI encoding

Hi,

I'm in the process if converting the data out of an old DOS-based
SunAccounts system (don't ask!) into SQL Server.

The data has been sent to me as a collection of hundreds of SunAccounts
backup files and it's a simple (yet extremely laborious!) process of opening
each backup file in turn, reading the file line by line, splitting it up
into its constituent parts, and then squirting it into SQL Server.

However, I'm experiencing a problem because Sun, being a DOS-based system,
uses ASCII encoding. Specifically, the old chestnut of the British pound
sign, which Sun considers to be hex 9c (i.e. Alt-156). However, Windows
using ANSI encoding sees this character as o instead of £ (Alt-163).

If I open the files into a StreamReader object without specifying an
encoding, C# appears to be using ASCII encoding. This has the effect of
ignoring the character completely which, in turn, throws the rest of the
import of of kilter because the file format is fixed-width, not delimted.

Therefore, can anyone please tell me what encoding I should use when reading
the file into a StreamReader object? I've tried several, but none appears to
work correctly so far. Some render the character as a question mark or a
blank square which, although not correct, at least doesn't stop the rest of
the import from working...

Any assistance gratefully received.

Mark
Dec 16 '05 #1
10 30034
hi Mark,
i've gone through such pain but my problem was little different. well
dude i would say you can not use StreamReader in your case. you have to
use BinaryReader to read whole file and than should use
"System.Text.ASCIIEncoding" to retrive the data into the WINDOWS ASCII
format.

this should work.

Dec 16 '05 #2

Mark Rae wrote:
Hi,

I'm in the process if converting the data out of an old DOS-based
SunAccounts system (don't ask!) into SQL Server.

The data has been sent to me as a collection of hundreds of SunAccounts
backup files and it's a simple (yet extremely laborious!) process of opening
each backup file in turn, reading the file line by line, splitting it up
into its constituent parts, and then squirting it into SQL Server.

However, I'm experiencing a problem because Sun, being a DOS-based system,
uses ASCII encoding. Specifically, the old chestnut of the British pound
sign, which Sun considers to be hex 9c (i.e. Alt-156).
ASCII is a 7-bit character system, and does not define any character
code higher than 127 (hex 7F). A quick poke at Google suggests that 9C
is the pound sign in Microsoft's DOS codepage 437. Hmm, or maybe 850.
Take a look at <http://en.wikipedia.org/wiki/Category:DOS_code_pages>
and links therefrom to decide for yourself.
However, Windows
using ANSI encoding sees this character as o instead of £ (Alt-163).
I'm really no expert on these matters, but I'm fairly sure that
'Windows using ANSI encoding' isn't specific enough to be amgibuous.

If I open the files into a StreamReader object without specifying an
encoding, C# appears to be using ASCII encoding. This has the effect of
ignoring the character completely which, in turn, throws the rest of the
import of of kilter because the file format is fixed-width, not delimted.

Therefore, can anyone please tell me what encoding I should use when reading
the file into a StreamReader object?
If I'm right about the original encoding being DOS codepage 437, you
should use the Encoding created by
System.Text.Encoding.GetEncoding(437). Or try 850.
I've tried several, but none appears to
work correctly so far. Some render the character as a question mark or a
blank square which, although not correct, at least doesn't stop the rest of
the import from working...

Any assistance gratefully received.


Encodings are a nightmare. Best of luck!

--
Larry Lard
Replies to group please

Dec 16 '05 #3
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...

Hi Larry,
System.Text.Encoding.GetEncoding(437)


Worked perfectly! Thanks very much.

Mark
Dec 16 '05 #4
<tu************@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
you can not use StreamReader in your case


Larry Lard's suggestion of System.Text.Encoding.GetEncoding(437) worked
perfectly.
Dec 16 '05 #5
Mark Rae <ma**@markN-O-S-P-A-M.co.uk> wrote:
I'm in the process if converting the data out of an old DOS-based
SunAccounts system (don't ask!) into SQL Server.

The data has been sent to me as a collection of hundreds of SunAccounts
backup files and it's a simple (yet extremely laborious!) process of opening
each backup file in turn, reading the file line by line, splitting it up
into its constituent parts, and then squirting it into SQL Server.

However, I'm experiencing a problem because Sun, being a DOS-based system,
uses ASCII encoding. Specifically, the old chestnut of the British pound
sign, which Sun considers to be hex 9c (i.e. Alt-156). However, Windows
using ANSI encoding sees this character as o instead of £ (Alt-163).


Neither of those are ASCII characters. ASCII is 7-bit. See
http://www.pobox.com/~skeet/csharp/unicode.html for more information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 16 '05 #6
<tu************@gmail.com> wrote:
i've gone through such pain but my problem was little different. well
dude i would say you can not use StreamReader in your case. you have to
use BinaryReader to read whole file and than should use
"System.Text.ASCIIEncoding" to retrive the data into the WINDOWS ASCII
format.


There's nothing wrong with using StreamReader here, but what's required
*isn't* ASCII. There's no such thing as "Windows ASCII" - there are
various 8-bit "extensions" to ASCII, in various "code pages"; they
aren't ASCII themselves, however.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 16 '05 #7
what i mean by WINDOWS ASCII is windows compatiable string. that what
was your problem right? you were not able to get DOS ASCII stirng
exactly in WINDOWS string. am i right?

Dec 17 '05 #8
Lucky wrote:
what i mean by WINDOWS ASCII is windows compatiable string. that what
was your problem right? you were not able to get DOS ASCII stirng
exactly in WINDOWS string. am i right?


As Jon said, there's no Windows ASCII, nor a DOS ASCII. There's only
ASCII. There's also no such thing as a Windows compatible string. It's
all just a matter of using the correct encoding.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Dec 17 '05 #9
Lucky <tu************@gmail.com> wrote:
what i mean by WINDOWS ASCII is windows compatiable string. that what
was your problem right? you were not able to get DOS ASCII stirng
exactly in WINDOWS string. am i right?


"DOS ASCII" and "WINDOWS ASCII" aren't precisely defined terms though.
DOS used lots of different default code pages depending on your region,
and so does Windows.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 17 '05 #10
> "DOS ASCII" and "WINDOWS ASCII" aren't precisely defined terms though.
DOS used lots of different default code pages depending on your region,
and so does Windows.

Joerg is right, there is no "DOS ASCII" and "WINDOWS ASCII", and ASCII is
very precisely defined.

ASCII = everything between 0-127, and is the same in all code pages (except
EBCDIC, but that is not ASCII, is EBCDIC :-)

ANSI code page = the Windows code pages. Same as "system code page". For Win
9x cannot be changed, for W2K, XP and newer it can be changed.
http://www.mihai-nita.net/20050611a.shtml

OEM code page = the DOS code pages. It is still used in Windows for console
applications.

See some info here:
http://blogs.msdn.com/michkap/archiv...08/369197.aspx
http://blogs.msdn.com/oldnewthing/ar...08/389527.aspx
http://www.mihai-nita.net/glossary.shtml

--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Dec 17 '05 #11

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

Similar topics

1
by: duzos duzos | last post by:
i need to connect to a dbf database with ansi/oem encoding the connection is ok but i have problem with page encoding the characters don't display as they should! does anyone have any...
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...
2
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
3
by: sjoshi | last post by:
I'm doig a test using XP English with LocalSettings set to Russian. When trying to open an XML file with ANSI encoding, I get errors. When I change the encoding to UTF8, I can read the file...
4
by: Nick | last post by:
Hi, I am trying to output a string of chinese characters as a text file. When I open a file for writing from VB, the file is automatically set to UTF-8 encoding (can tell by opening the file...
4
by: Richard | last post by:
I need to use ANSI encoding in VB.NET, but can't seem to find it, can anyone help, I can only find these ASCII UTF7 UTF8 default BigEndianUnicode Unicode, and a method getEncoding(codepage...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.