What is the maximum string length

I created this little script to verify the maximum length of a string. It might be more, but some of the functions for manipulating strings use apparently 32 bit signed integers, amongst the Length(s), so I cannot test further than a string length of 2,147,483,647 bytes (being (2 ^ 31) - 1)

Initialization
var s : string
    i : integer
    
    Print ("Start: " + FormatTime(ClockTime(), "%H:%M:%S"))

    s = "01234567"
    for i = 0; i < 27; i = i + 1 do
        s = s + s
    end
    s = s + CopySubstring (s, 0, Length(s) - 9) + "ABCDEGHI"

    Print ("Stop: " + FormatTime(ClockTime(), "%H:%M:%S"))
    Print (Length(s))
    Print (CopySubstring (s, Length(s) - 16, 16)) // Should be "70123456ABCDEFGHI"
End

As it turns out, the max length is exactly ‘MAXINT’ bytes (signed), so to be more precise (2 ^ 31) - 1 bytes == 2,147,483,647 bytes.

Shame on you! Not even cared for using an unsigned int :rofl: ?! (just kidding). I think this will do more than nicely.

Because the memory has to be allocated, bigger strings will be slower to assign. They are also a lot slower to use.