Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-09

How to find the byte offset of the n-th character in an UTF-8 string?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Roland Schaefer

Hi all,
I have a situation where I internally work with AnsiStrings but need to convert them to UTF-8 before passing them to libpango, which I do with AnsiToUtf8(). I then need the byte offset of one specific (varying) character in the UTF-8 string, which is not trivially available since some characters are encoded in 2 bytes. Before I start my own hacks: Is there a nice way of finding the byte offset of the n-th character in an UTF-8 string?

Thanks a lot.
Regards
Roland

Reply by email

Martin
to Roland Schaefer

Have a look at LCLProc in lazarus.

function UTF8CharToByteIndex(UTF8Str: PChar; Len, CharIndex: PtrInt):
PtrInt;
Roland Schaefer wrote 16 lines
Hi all, I have a situation where I internally work with AnsiStrings but need to convert them to UTF-8 before passing them to libpango, which I do with AnsiToUtf8(). I then need the byte offset of one specific (varying) character in the UTF-8 string, which is not trivially available since some characters are encoded in 2 bytes. Before I start my own hacks: Is there a nice way of finding the byte offset of the n-th character in an UTF-8 string? Thanks a lot. Regards Roland _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email