Mapping string into structure using C#

  • Thread starter Thread starter rt
  • Start date Start date
R

rt

Hello,

I was wondering if it is possible to create a structure which "overlays" a
string? For example, I have a string of formatted data and I would like to
map this string onto a structure to obtain the values. Below is an example
that contains only a few items but the "real thing" has around a hundred
items (I have no control of the input so changing it is not an option, I
just need to process it).

input string: "Item1BeginItem2ThisIsItem3"

Item1 is always 5 characters
Item2 is always 10 characters
Items3 is always 11 characters

struct MyMap
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=5)]
public string Item1;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)]
public string Item2;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=11)]
public string Item3;
};

Now, I'm not sure if it is possible to map the input string to an instace of
MyMap. Is there another option besides MarshalAs?

Thanks,

Rick
 
Hi,

Do you still have any concern?
Please feel free to let me know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top