[Solved] 6-position text (1 of them accented) returns length 7 lazarus / 21-General ---------------------------------------------------------------------- MiquelMus · 2022-11-04 11:41 I need to process a text, position by position, but if it contains accented letters or characters like 'ñ', the length function does not return the correct length. Specifically 'Nación' which is 6 positions long returns a length of 7. If we loop from 1 to 7 character by character it returns 'N', 'a', 'c', 'i', '', '', ' n' and as numeric values for each character '78', '97', '99', '105,'195','179' and '110'. It is possible to treat a variable with accented characters position by position? Thank you very much. I send a complete test in .zip and a reduced set below. procedure TForm1.btnProClick(Sender: TObject); var   sLbl: ansiString;   iLen: integer;   i: integer; begin   sLbl := 'Nación';   txLbl.Text := sLbl;                     //'Nación   iLen := Length(sLbl);                   //7   tLen.Text := intToStr(iLen);            //7   t1.Text := sLbl[1];                     //'N'   t2.Text := sLbl[2];                     //'a'   t3.Text := sLbl[3];                     //'c'   t4.Text := sLbl[4];                     //'i'   t5.Text := sLbl[5];                     //''   t6.Text := sLbl[6];                     //''   t7.Text := sLbl[7];                     //'n'   t1b.Text := IntToStr(integer(sLbl[1])); //78   t2b.Text := IntToStr(integer(sLbl[2])); //97   t3b.Text := IntToStr(integer(sLbl[3])); //99   t4b.Text := IntToStr(integer(sLbl[4])); //105   t5b.Text := IntToStr(integer(sLbl[5])); //195   t6b.Text := IntToStr(integer(sLbl[6])); //179   t7b.Text := IntToStr(integer(sLbl[7])); //110 end; ---------------------------------------------------------------------- Bart · 2022-11-04 12:04 Utf8Length() will give you the answer of 6 There are several functions in LazUtf8 unit you can use to handle UTF8 encoded strings. The "lazy" way to iterate would be something like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  i: Integer;  UTF8Char: Stringbegin  for i := 1 to Utf8Length(S) do  begin    Utf8Char := Utf8Copy(S,i,1);    DoSomethingWith(Utf8Char);  end;end;  Suffices for relative short strings, but don't use that on a text of several MB's... Bart ---------------------------------------------------------------------- MiquelMus · 2022-11-04 13:05 [Solved] Thanks Bart, it works perfectly, just as you indicated. ---------------------------------------------------------------------- alpine · 2022-11-04 14:07 See also this one: https://forum.lazarus.freepascal.org/index.php/topi c,57891.msg431008.html#msg431008