I've extended the little test program:
```
program Project1;
{$mode objfpc}
{$longstrings on}
uses sysutils;
var S: Utf8string;
begin
S := 'äfoo';
Writeln(PtrUInt(Pointer(S)));
Writeln(PtrUInt(Pointer(String(S))));
Writeln('DefaultSystemCodePage = ', DefaultSystemCodePage);
Writeln('S codepage = ', StringCodePage(S));
Writeln('String(S) codepage = ', StringCodePage(String(S)));
Writeln('Index = ', String(S).IndexOf('f'));
end.
```
Thank you for pointing me to the shortstring/longstring issue. The string pointers are equal and there is no indication for a codepage conversion as part of the cast.
However, the remaining questions are:
1) Is the explicit cast guaranteed to preserve the underlying string and its dynamic codepage without conversion, or is this only an implementation detail?
2) Are there any plans for making the string helpers available with Utf8String and RawByteString, too?
Thanks,
Thomas
Earlier message 20 lines
----- Original Message -----
From: Bart via fpc-pascal
To: FPC-Pascal users discussions
Sent: Friday, August 28, 2026, 18:08:36
Subject: [fpc-pascal] TStringHelper and Utf8String
On Fri, Aug 28, 2026 at 3:43 PM Bart wrote:
> As expected?
> In the Utf8String 'f' will be at index 3, since the 'ä' will take up 2
> bytes in UTF8-encoding.
Seems I'm wrong.
IndexOf() is zero-based, so 2 is indeed the correct value.
I would have expected/feared that casting to String() would trigger a
codepage conversion to CP_ACP, which is a 1-byte encoding by default
on
Bart