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
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