Small String question about Island

(Theo) #1

Is a string in island immuatble (like in .Net) or is it just and array of char that I can mutate.
Note: When it is the last, i have found my reason to use it.

(marc hoffman) #2

the native String type provided by Island RTL is immutable, same as in .NET and on all other Elements platforms. You can. of course roll our own, or use Delphi RTL’s string (which is a mutable value type, similar tho how it is in Delphi too.

Note that there are huge performance benefits for regular strings being immutable compared to Delphi’s approach though, and its most usually better to rely on other more specialized types (such as StringBuilder or, indeed, an array) when needing to do mutations…

(Theo) #3

Yes, I know that.

But in some cases a mutable string has huge performance benefits.
Replacing a character on a specific position without copying the string is one of them.

(Carlo Kok) #4

Yes. For those cases, an array of Char or StringBuilder can be used.