Hi !
I want to load an old Pascal-Dos-File where
records stand in. When i view the file
in a HEX-Editor it's clear how to acces these
Strings and chars in that file. Since these
are old 8BIT chars (C# uses 16BIT) i read
the file bytewise and convert the bytes
to chars using ENCODER.getChar s(). From the chars
i make a big String which should be the file as
i see in the HEX-Editor. But there are many errors
in it, as the getChars() Method seem not to
convert all the chars (bytes) propably.
Any suggestions ?
Please Help,
Thanks,
nick 8 3151
Nick <ni**@winger.at > wrote: I want to load an old Pascal-Dos-File where records stand in. When i view the file in a HEX-Editor it's clear how to acces these Strings and chars in that file. Since these are old 8BIT chars (C# uses 16BIT) i read the file bytewise and convert the bytes to chars using ENCODER.getChar s(). From the chars i make a big String which should be the file as i see in the HEX-Editor. But there are many errors in it, as the getChars() Method seem not to convert all the chars (bytes) propably. Any suggestions ?
You need to use the right Encoding instance when grabbing the string
(you can usually use GetString rather than GetChars). What encoding was
it written in?
(Alternatively, just use a StreamReader with the appropriate encoding
to start with - you'll still need to know what encoding was used.)
Note that strings are character data, whereas when you're viewing the
file with a hex editor you're viewing it as binary data, possibly with
a text interpretation (in whatever encoding the hex editor feels is
appropriate) available too.
See http://www.pobox.com/~skeet/csharp/unicode.html for more
information about this whole topic.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
hi !
you mentioned this text interpretation of the
hex editor. so in the hex editor every BYTE
is a character and that's exactly what i want.
because in the hex editor i can read all the info
i want to read out of the file, but with c# i
can't convert every byte. can the hex editor check
the encoding, or is this "no" encoding when every byte
is a character.
thanks,
nick
Nick <ni**@winger.at > wrote: you mentioned this text interpretation of the hex editor. so in the hex editor every BYTE is a character and that's exactly what i want. because in the hex editor i can read all the info i want to read out of the file, but with c# i can't convert every byte. can the hex editor check the encoding, or is this "no" encoding when every byte is a character.
The hex editor can't really check the encoding because (say) *every*
file is a valid ISO-8859-1 file, just as an example.
When every byte is a character you still need to interpret that byte as
a character - and that depends on the encoding. The hex editor may well
be assuming an encoding such as Cp1252, or (for an old DOS file) Cp437.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
okay :o)
i have the following code:
StreamReader sr = new StreamReader(fi leName,
System.Text.Uni codeEncoding.AS CII);
String s = sr.ReadToEnd();
sr.Close();
for (int i=0;i<3000;i++)
{
Console.WriteLi ne("Byte "+i+": "+s[i]);
}
and, of course because of the wrong encoding,
i get the following error output:
Byte 0: Byte 86: 244:
Byte 323: 1: te 480: 637: Byte 716: : e 873:
Byte 874:
Byte 875:
it leaves some bytes undecoded.
but with the few encodings in System.Text.Enc oding
i can't get it right.
how can i set other encodings, for example this
Cp1252 or Cp437 ?
thanks,
nick
Nick <ni**@winger.at > wrote: okay :o) i have the following code:
StreamReader sr = new StreamReader(fi leName, System.Text.Uni codeEncoding.AS CII);
UnicodeEncoding .ASCII is a very weird way of writing that - I've seen
people use ASCIIEncoding.A SCII or UnicodeEncoding .Unicode, but never
mixing the two. I just write Encoding.ASCII, as that's where it's
actually declared.
String s = sr.ReadToEnd(); sr.Close();
for (int i=0;i<3000;i++) { Console.WriteLi ne("Byte "+i+": "+s[i]); }
and, of course because of the wrong encoding, i get the following error output: Byte 0: Byte 86: 244: Byte 323: 1: te 480: 637: Byte 716: : e 873: Byte 874: Byte 875:
it leaves some bytes undecoded. but with the few encodings in System.Text.Enc oding i can't get it right. how can i set other encodings, for example this Cp1252 or Cp437 ?
Use Encoding.GetEnc oding - see the documentation for it for more
information. You might use Encoding.GetEnc oding (1252) for instance, or
Encoding.GetEnc oding(437).
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
hi,
all these getencoding methods seem to work,
i get no exception, but i can't still read
the textfile the way i want ?!?
i've tried it now with the simple notepad
(which could/should be easily implemented)
and it works with ANSI and UTF8. I can
read the few things i would need.
but when i read it with the StreamReader
and use Encoding.UTF8 or ANSI i get the same
not working output as if i would use ascii
or unicode (which are both not displaying
the data the way i would need it in notepad)
what could be so hard for c# reading the file
like notepad does or just interpret every
byte as a ascii character like the hex editor
does ?
thanks,
nick
Nick <ni**@winger.at > wrote: all these getencoding methods seem to work, i get no exception, but i can't still read the textfile the way i want ?!? i've tried it now with the simple notepad (which could/should be easily implemented) and it works with ANSI and UTF8. I can read the few things i would need.
Reading it as UTF8 should give radically different results to reading
it as "ANSI" (where "ANSI" means different things depending on your
region).
but when i read it with the StreamReader and use Encoding.UTF8 or ANSI i get the same not working output as if i would use ascii or unicode (which are both not displaying the data the way i would need it in notepad)
what could be so hard for c# reading the file like notepad does or just interpret every byte as a ascii character like the hex editor does ?
Interpreting every byte as an ASCII character is easy - just use
Encoding.ASCII. You then run into trouble with bytes > 127 though, as
ASCII doesn't have values > 127.
One thing to consider is whether or not you're accurately examining the
data after reading it in. I find the best way to find out exactly what
characters I've got in a string is to print out their Unicode values
one at a time, as numbers, and look them up at http://www.unicode.org
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
nick <ni**@winger.at > wrote: now i have read a lot of articles in the net and tried a lot of things, nothing helped. now i've opened the file with notepad using ANSI encoding and saved it with ending .txt NOW it worked in c#, and i could read the info. so what's the difference ?
Without knowing exactly what you're doing or what's in the file, it's
hard to say.
in explorer both files have the same size. i opened them with hex edit and the ONLY difference is that every "00" hex pair is replaced by "20" hex. hmmm
and that's the problem with c# reading the file ?
I doubt it - but it may be part of the problem with how you were
displaying it.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ohaya |
last post by:
Hi,
I'm a real newbie, but have been asked to try to fix a problem in one of
our JSP pages that is suppose to read in a text file and display it.
From my testing thus far, it appears this page is somehow hanging when
relatively large file is used.
My original intent was to try to just add a check for file size, and
error out somehow if the file was "too" large, but in looking at the
|
by: jamait |
last post by:
Hi all,
I m trying to read in a text file into a datatable...
Not sure on how to split up the information though, regex or substrings...?
sample:
Col1 Col2 Col3
Col4
A0012430 REKAL TVÄTTMEDEL EKOMAX 0,5L ST 75.9000
|
by: syntax |
last post by:
hi, i want to read a file using fread() in equal chunks through a for
loop so that at the last call i dont get error..which way, i should
read it?
let me give an example, suppose i have 100 chars, i can read it in 50
chars for twice or 10 chars in ten times or 25 chars for 4
times...like this. Here, file size, i.e 100 chars is known to
me....but if the file size is unknown then how can i read in equal
chunks so that at the last call i...
|
by: Drew Berkemeyer |
last post by:
Hello,
I'm using the following code to read a text file in VB.NET.
Dim sr As StreamReader = File.OpenText(strFilePath)
Dim input As String = sr.ReadLine()
While Not input Is Nothing
strReturn += input + vbCrLf
input = sr.Read
|
by: Nick |
last post by:
Hi !
I want to load an old Pascal-Dos-File where
records stand in. When i view the file
in a HEX-Editor it's clear how to acces these
Strings and chars in that file. Since these
are old 8BIT chars (C# uses 16BIT) i read
the file bytewise and convert the bytes
to chars using ENCODER.getChars(). From the chars
i make a big String which should be the file as
i see in the HEX-Editor. But there are many errors
| |
by: Andrea Gavana |
last post by:
Hello NG,
that may sound a silly question, but I didn't find anything really
clear about the issue of reading unformatted big endian files with
Python. What I was doing till now, was using Fortran to read those
files and compile this Fortran extension using F2PY. Now that it seems
that no possible combinations of Fortran/C compilers actually *work*
with Python 2.4 on Windows XP, I was trying to translate the Fortran
subroutine to...
|
by: vlsidesign |
last post by:
I am a newbie and going through "The C programming language" by
Kernighan & Richie on my own time (I'm not a programmer but I want to
learn because it can save me time in my normal job, and it is kind of
fun). As I go through the book, I seek to do all the exercises because
they are very useful, and good, but it seems like I am just stumbling
through somewhat. In particular, I don't really know how to think about
"catching errors", or how...
|
by: Freddy Coal |
last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all
the file in a String.
I make this function for make that:
'--------------------------
Public Shared Function Read_bin(ByVal ruta As String)
Dim cadena As String = ""
Dim dato As Array
If File.Exists(ruta) = True Then
|
by: efrenba |
last post by:
Hi,
I came from delphi world and now I'm doing my first steps in C++. I'm
using C++builder because its ide is like delphi although I'm trying to
avoid the vcl.
I need to insert new features to an old program that I wrote in delphi
and it's a good opportunity to start with c++.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |