Re: Reading an Ascii string

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Check out the System.Text Namespace, specifically the Encoding, Encoder, and
Decoder classes.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.


"John" <-> wrote in message news:OMR74pooGHA.3304@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

I'm a beginner is using C# and .net.

I have big legacy files that stores various values (ints, bytes, strings)
and want to read them into
a C# programme so that I can store them in a database. The files are
written by a late 1980's PC
Pascal programme, for which I don't have the source code. I've managed to
reverse engineer the file
format.

The strings are stored as Ascii in the file, with the first byte
indicating the string length, and
the rest are the Ascii (ie 8-bit) characters. The string length is always
0, 20 or 40 characters
(never any more) and strings are end-padded with space characters where
necessary.

What is the best way to quickly read a string and get rid of the space
padding at the end? To make
sure I can read them correctly, I'll put them in a text box. I assume the
string used in a test box
uses 16-bit characters (unicode?) but I may be wrong here. When I'm happy
I can read them correctly,
I'll get rid of the text box and store them directly in the database. Is
it best to store it in the
database as unicode? I'm tempted to use Ascii for efficiency.

I was thinking of using a binary reader (_br) to extract from the file.
That should be fine for
everything, but I don't know how to cope the the Ascii strings.




.



Relevant Pages

  • Re: Null-terminated strings: the final analysis.
    ... irrelevant to a discussion of C strings. ... contain any characters other than '\0', ... Yes, but you can't store a null character in the middle of a string, ... If, because of some requirement outside the C language, I want to ...
    (comp.lang.c)
  • Re: XLL, C++ and dates
    ... standard and uses 4 bytes to store the data. ... bits (2 byes) but I'm told they are being stored as long which is also ... Characters are 1 byte per character but I believe the ... strings are passed as pointers and must be prepared the same way in XLOPER. ...
    (microsoft.public.excel.programming)
  • RE: HeapFree() Failure
    ... HeapAllocand HeapFreecalls with GlobalAlloc() and GlobalFree ... globally defined strings it declares like so: ... Sixteen bytes are successfully allocated to store pointers to ...
    (microsoft.public.windowsce.embedded)
  • Re: RGB LEDs
    ... or ask for 'pale goldenrod' and the LEDs are set that way. ... those strings... ... You don't need to store the entire table as raw ASCII. ...
    (sci.electronics.design)
  • Re: Fibonacci numbers
    ... | Of course there is the question of how to store the number. ... Instead of using characters to represent decimal digits, ... It is easier than dealing with characters, as you don't need to offset ... the way that we write numbers in strings. ...
    (comp.lang.cpp)