How to declare a fixed length string
JRoark
Posts: 1,215
I'm trying to figure-out how to declare a fixed length string in 5.9.9. What I'm after is something like this:
class tempType Var1 as ulong Var2 as ushort Var3 as string(128) end class dim NewType as tempType NewType.Var3 = "This is a test" print NewType.Var3
The goal here is to always have 128 bytes reserved for Var3. Ideally I'd also like it never to be garbage-collected... just a static array of bytes that "looks like" a regular string. Any thoughts about how to make this work?
Comments
how about byte(128) ?
Mike
You can alias the string as a pointer to the ubyte array, but then you cannot assign to it as every assign creates a new string with a new pointer. In the class you can write your own methods for such a "string"
The result:
After aliasing a$ as the pointer to a and updating a, you can print a$.
After updating a$ the pointer to a$ is no longer the pointer to a, so after assigning the new value, the pointer also changed (and was allocated, etc...)
And string(128) is an array of 128 strings (= 128 pointers)