|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Parsing a fixed length record into fieldsI'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? 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? | 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? > | > > > 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? >> | >> >> >>
Please do NOT sign the VB.COM petition
What am I doing wrong - Trying to update Option Strict disallows late binding, need to update code Visual Basic App Memory Issue How to create a zoom feature in Vb.Net Passing objects ByVal vs ByRef Invert an Arraylist.Sort() SharpZipLib Collection Class Serialization Excel In VB.net |
|||||||||||||||||||||||