I'm trying to write a quick migrate tool to convert our old binary flat DB
to SQL Server. I thought I would use C# and get started with a managed
language. I have found plenty of examples of how to read a binary file into
an array of bytes, great. But what do I do with it then?
How can I copy n bytes from my data byte[] into the new, managed float
object that I just declared? What am I missing? Any ideas?
Thanks for any help, this is one of those problems that once solved will
open the flood gates of success ;)
-Steve 7 1235
Steve,
You can use the static methods on the BitConverter class to convert to
value types (assuming the byte layout is the same).
For strings, you will want to use a class derived from
System.Text.Encoding, and then pass the bytes to the GetString method (based
on what encoding the strings are stored in).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"SteveK" <as***@asdfasdfsd.com> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl... I'm trying to write a quick migrate tool to convert our old binary flat DB to SQL Server. I thought I would use C# and get started with a managed language. I have found plenty of examples of how to read a binary file into an array of bytes, great. But what do I do with it then?
How can I copy n bytes from my data byte[] into the new, managed float object that I just declared? What am I missing? Any ideas?
Thanks for any help, this is one of those problems that once solved will open the flood gates of success ;)
-Steve
Thanks Nicholas,
I have BitConverter working nicely, I will look into the Encoding solution
you suggested.
Thanks again!
Steve
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl... Steve,
You can use the static methods on the BitConverter class to convert to value types (assuming the byte layout is the same).
For strings, you will want to use a class derived from System.Text.Encoding, and then pass the bytes to the GetString method
(based on what encoding the strings are stored in).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"SteveK" <as***@asdfasdfsd.com> wrote in message news:OW**************@TK2MSFTNGP14.phx.gbl... I'm trying to write a quick migrate tool to convert our old binary flat
DB to SQL Server. I thought I would use C# and get started with a managed language. I have found plenty of examples of how to read a binary file into an array of bytes, great. But what do I do with it then?
How can I copy n bytes from my data byte[] into the new, managed float object that I just declared? What am I missing? Any ideas?
Thanks for any help, this is one of those problems that once solved will open the flood gates of success ;)
-Steve
Why is class Encoding abstract? Seems like the base class has what I
need... confused.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl... Steve,
You can use the static methods on the BitConverter class to convert to value types (assuming the byte layout is the same).
For strings, you will want to use a class derived from System.Text.Encoding, and then pass the bytes to the GetString method
(based on what encoding the strings are stored in).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"SteveK" <as***@asdfasdfsd.com> wrote in message news:OW**************@TK2MSFTNGP14.phx.gbl... I'm trying to write a quick migrate tool to convert our old binary flat
DB to SQL Server. I thought I would use C# and get started with a managed language. I have found plenty of examples of how to read a binary file into an array of bytes, great. But what do I do with it then?
How can I copy n bytes from my data byte[] into the new, managed float object that I just declared? What am I missing? Any ideas?
Thanks for any help, this is one of those problems that once solved will open the flood gates of success ;)
-Steve
You create instances of classes derived from Encoding which represent your
encoding:
new UnicodeEncoding().GetString(arr)
new UTF8Encoding().GetString(arr)
and so on
Użytkownik "SteveK" <as***@asdfasdfsd.com> napisał w wiadomo¶ci
news:uc**************@TK2MSFTNGP09.phx.gbl... Why is class Encoding abstract? Seems like the base class has what I need... confused.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:%2****************@TK2MSFTNGP10.phx.gbl... Steve,
You can use the static methods on the BitConverter class to convert
to value types (assuming the byte layout is the same).
For strings, you will want to use a class derived from System.Text.Encoding, and then pass the bytes to the GetString method (based on what encoding the strings are stored in).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"SteveK" <as***@asdfasdfsd.com> wrote in message news:OW**************@TK2MSFTNGP14.phx.gbl... I'm trying to write a quick migrate tool to convert our old binary
flat DB to SQL Server. I thought I would use C# and get started with a
managed language. I have found plenty of examples of how to read a binary
file into an array of bytes, great. But what do I do with it then?
How can I copy n bytes from my data byte[] into the new, managed float object that I just declared? What am I missing? Any ideas?
Thanks for any help, this is one of those problems that once solved
will open the flood gates of success ;)
-Steve
lukasz <bb****@op.pl> wrote: You create instances of classes derived from Encoding which represent your encoding: new UnicodeEncoding().GetString(arr) new UTF8Encoding().GetString(arr) and so on
Except that usually using the properties on Encoding is nicer:
Encoding.Unicode.GetString(arr);
Encoding.UTF8.GetString(arr);
I only create a new Encoding instance if I need it to have specific
parameters which the version retrieved by the property may not.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
SteveK <as***@asdfasdfsd.com> wrote: Why is class Encoding abstract? Seems like the base class has what I need... confused.
See http://www.pobox.com/~skeet/csharp/unicode.html
You might also want to consider using BinaryReader instead of
BitConverter. It may make some things easier for you.
Finally, BitConverter has a problem - it only works with one
endianness, and that can't be set :( I have a library which solves this
problem: http://www.pobox.com/~skeet/csharp/miscutil
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thanks Jon, that is a good thing to have pointed out ;)
I will look into this stuff more...
-SK
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... SteveK <as***@asdfasdfsd.com> wrote: Why is class Encoding abstract? Seems like the base class has what I need... confused.
See http://www.pobox.com/~skeet/csharp/unicode.html
You might also want to consider using BinaryReader instead of BitConverter. It may make some things easier for you.
Finally, BitConverter has a problem - it only works with one endianness, and that can't be set :( I have a library which solves this problem: http://www.pobox.com/~skeet/csharp/miscutil
-- Jon Skeet - <sk***@pobox.com> 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: Khuong Dinh Pham |
last post by:
I have the contents of an image of type std::string. How can I make a
CxImage object with this type.
The parameters to CxImage is:
CxImage(byte* data, DWORD size)
Thx in advance
|
by: Ben Terry |
last post by:
What's the most efficient way to transfer data from a byte to a struct?
The struct is rather complex--contains other structs as well as byte
members. I've tried to use Marshal.Copy and an IntPtr...
|
by: TJO |
last post by:
Can someone recomend a good technique for removing BOF and EOF markers from
a byte? I am passing a byte thru an FTP socket. I am serializing an
object into a byte and then adding an EOF marker...
|
by: Gianmaria I. |
last post by:
Hi,
having a BitArray, how can i extract bits to create a System.byte
as in the example...
With
BitArray bits
and
Byte myNewByte
|
by: twawsico |
last post by:
I have a piece of code that needs to read the contents of a binary file
(that I've created with another app) into an array of structures. The
binary data in the file represents just a series of...
|
by: Terry |
last post by:
In the code below, I open a file using filestream, copy it to a byte
array, and the write that array out to a new file. But when I check
the size of the original file and the new file, the new...
|
by: marfi95 |
last post by:
Hi all.
I need to copy a byte array into a string, but starting at a specific
location in the byte array. This is where I get hung up. For example if
my byte array is (100) big, I might want to...
|
by: O.B. |
last post by:
I'm trying to do a static_cast at runtime in C# and as I understand it,
"as" is the keyword to use. Unfortunately, the compiler is trying to do
the cast a compilation time. See below.
/*...
|
by: Rainer Queck |
last post by:
Hi NG,
is there a way to copy a buffer pointed to by a IntPtr directly into a two
dimensional byte-array?
I tried this, what obviously doesn't work:
byte image = new byte;
IntPtr p =...
|
by: Scott Townsend |
last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent
it to be in specific places (not yet 100% defined).
I wanted to create a structure/class with all of the data in it...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| | |