Home All Groups Group Topic Archive Search About

Parsing a fixed length record into fields

Author
6 Apr 2005 7:39 PM
John B
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?

Author
6 Apr 2005 8:30 PM
steve
google much? ;^)

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

http://www.codeproject.com/info/error404.asp?404;http://www.codeproject.com/useritems/TextFileParser.asp


Show quoteHide quote
"John B" <Jo***@discussions.microsoft.com> wrote in message
news:328F26B3-81A8-49BE-AC42-B3F5F7BC14B4@microsoft.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?
|
Author
6 Apr 2005 9:41 PM
John B
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.

Show quoteHide quote
"steve" wrote:

> google much? ;^)
>
> too many examples to choose from...here's one from the code project.
>
> http://www.codeproject.com/info/error404.asp?404;http://www.codeproject.com/useritems/TextFileParser.asp
>
>
> "John B" <Jo***@discussions.microsoft.com> wrote in message
> news:328F26B3-81A8-49BE-AC42-B3F5F7BC14B4@microsoft.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?
> |
>
>
>
Author
6 Apr 2005 10:45 PM
Stephany Young
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.


Show quoteHide quote
"John B" <Jo***@discussions.microsoft.com> wrote in message
news:5228D198-98B4-433A-8BDA-F8F8AE87C598@microsoft.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/error404.asp?404;http://www.codeproject.com/useritems/TextFileParser.asp
>>
>>
>> "John B" <Jo***@discussions.microsoft.com> wrote in message
>> news:328F26B3-81A8-49BE-AC42-B3F5F7BC14B4@microsoft.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?
>> |
>>
>>
>>