473,386 Members | 1,736 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,386 software developers and data experts.

Parsing a fixed length record into fields

I'm receiving a fixed length string with fixed length fields that I need to
break apart. Ideally I'd like to take the string and put it into a Structure
and then access the individual fields from there.

I tried converting the string to a byte array and then used a
Marshal.PtrToStructure to do the move but get a null reference exception in
mscorlib.dll. All the paramers look valid going into the call.

Any ideas how to fix the error or is there another way to do this?

Nov 21 '05 #1
3 2276
google much? ;^)

too many examples to choose from...here's one from the code project.

http://www.codeproject.com/info/erro...FileParser.asp
"John B" <Jo***@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
| I'm receiving a fixed length string with fixed length fields that I need
to
| break apart. Ideally I'd like to take the string and put it into a
Structure
| and then access the individual fields from there.
|
| I tried converting the string to a byte array and then used a
| Marshal.PtrToStructure to do the move but get a null reference exception
in
| mscorlib.dll. All the paramers look valid going into the call.
|
| Any ideas how to fix the error or is there another way to do this?
|
Nov 21 '05 #2
Seems like a lot of work when I can just put a dozen substrings and get the
same result. Seems like all this is a step backwards. In the "olden days"
you could map into a buffer and access the data.

"steve" wrote:
google much? ;^)

too many examples to choose from...here's one from the code project.

http://www.codeproject.com/info/erro...FileParser.asp
"John B" <Jo***@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
| I'm receiving a fixed length string with fixed length fields that I need
to
| break apart. Ideally I'd like to take the string and put it into a
Structure
| and then access the individual fields from there.
|
| I tried converting the string to a byte array and then used a
| Marshal.PtrToStructure to do the move but get a null reference exception
in
| mscorlib.dll. All the paramers look valid going into the call.
|
| Any ideas how to fix the error or is there another way to do this?
|

Nov 21 '05 #3
Absolutely John. Unfortunately, acedemic and philosophical niceties can
often loose sight of common sense.

The String methods .Substring and .Trim will achieve what you want with
perfectly understandable code.

You might like to browse for a thread, a few days ago, regarding this
subject where some tests showed that the Microsoft.VisualBasic.Mid and
Microsoft.VisualBasic.Trim functions can be more efficient than the
String.Substring and String.Trim methods.
"John B" <Jo***@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
Seems like a lot of work when I can just put a dozen substrings and get
the
same result. Seems like all this is a step backwards. In the "olden
days"
you could map into a buffer and access the data.

"steve" wrote:
google much? ;^)

too many examples to choose from...here's one from the code project.

http://www.codeproject.com/info/erro...FileParser.asp
"John B" <Jo***@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
| I'm receiving a fixed length string with fixed length fields that I
need
to
| break apart. Ideally I'd like to take the string and put it into a
Structure
| and then access the individual fields from there.
|
| I tried converting the string to a byte array and then used a
| Marshal.PtrToStructure to do the move but get a null reference
exception
in
| mscorlib.dll. All the paramers look valid going into the call.
|
| Any ideas how to fix the error or is there another way to do this?
|

Nov 21 '05 #4

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

Similar topics

18
by: Wade Leftwich | last post by:
Every couple of months I have a use for the experimental 'scanner' object in the re module, and when I do, as I did this morning, it's really handy. So if anyone is counting votes for making it a...
2
by: Greg Lindstrom | last post by:
Hello- I'm creating fixed-length record layouts for various record translations I need to perform. I have been using a home-grown object, "FixedLengthRecord" for about 4 years now and am very...
9
by: gov | last post by:
Hi, I've just started to learn programming and was told this was a good place to ask questions :) Where I work, we receive large quantities of data which is currently all printed on large,...
21
by: Scott Marquardt | last post by:
What are some good strategic approaches to using freeform text fields for data that needs to be queried? We have a product whose tables we can't change, and I need to count on a "description" field...
8
by: Jami Bradley | last post by:
Hi, I'm looking for an efficient way to do this, because I know it will be heavily used :-) I have a fixed width string and I need to substitute a substring of characters with new values. I...
3
by: ecov | last post by:
Is there any easy way to read into a dataset a file that was created from a BCP command. The file is in a fixed length format. I would also like to be able to write out a dataset to the same type...
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
1
by: htres | last post by:
Hello, I'm new to programming and C#, so please bear with my ignorance! I need to extract jpeg images and header data from a binary file. The binary file is formatted with several fixed...
2
by: Jim | last post by:
I need to write a text file that has fixed length fields resulting in a fixed length record. What I'd like to see is something like Cobol (gag) uses 01 rec. 02 field1 pic x(02. 02 field2 pic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
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 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.