[Lazarus] How to use strings properly with fixes_1_6 and FPC 3.0.0?

Jürgen Hestermann juergen.hestermann at gmx.de
Fri Oct 21 12:48:23 CEST 2016

Am 2016-10-21 um 12:05 schrieb Gabor Boros via Lazarus:
 > 2016. 10. 21. 10:25 keltezéssel, Juha Manninen via Lazarus írta:
 >> * Please read the wiki page ...
 > I read, I read but if contains buggy example... ;-)

Yes, this can be very frustrating...
Documenation is one of the major drawbacks of Free Pascal/Lazarus.

 > I need a quick and a rock solid solution. Is it good solution if replace all Length, Copy, Delete with UTF8Length, UTF8Copy, UTF8Delete and read the strings through with this for i:=1 to UTF8Length(s) do Write(UTF8Copy(s,i,1))?
 > I do not want to think of where Length, Copy, Delete is good and where UTF8* needed.

I think if you want to use unicode (which is IMO unavoidable today)
then UTF8 is a good choice (see http://utf8everywhere.org )
and then you have to cope with the encoding anyway.
Byte and character position are not related anymore,
neither in UTF-8 nor in UTF-16.
Only UTF-32 provides this but wastes a lot of memory.

But in many cases you do not need the character position.
To find a substring, you only need the byte position.
You can then delete this character from the byte position
and insert another one. Of course, you need to delete as many
bytes as the character consists of.

If you realy need the character position/length, then
you have to use UTF8Length/UTF8Copy/etc.
But as said: It is only needed in special circumstances.
Still you have to know when to use what.

More information about the Lazarus mailing list