[SOLVED] - Maybe a problem with .length :S:S lazarus / 31-LCL ---------------------------------------------------------------------- esvignolo · 2017-03-06 17:10 Hello! I have a question with the handling of strings. Punctually, the length of the same with accented characters. Please look at attachament. In the attachment you can see a screenshot, from the code below. Where there are two TEdit with the same text (with the difference that in one of them, this one with accents), but the length of the same is different, I thought that could be the codification, but both are in UTF8. 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, LConvEncoding; type   { TForm1 }   TForm1 = class(TForm)    Edit1: TEdit;    Edit2: TEdit;    Label1: TLabel;    Label2: TLabel;    procedure Edit1Change(Sender: TObject);    procedure Edit2Change(Sender: TObject);    procedure FormShow(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Edit1Change(Sender: TObject); begin   Label1.Caption:='Length: '+intToStr(Length(edit1.Text))+'  GuessEncoding: '+GuessEncoding(edit1.Text);end;  procedure TForm1.Edit2Change(Sender: TObject);begin    Label2.Caption:='Length: '+intToStr(Length(edit2.Text))+'  GuessEncoding: '+GuessEncoding(edit2.Text);end; procedure TForm1.FormShow(Sender: TObject);begin    Edit1Change(self);    Edit2Change(self);end; end.   Thanks! ---------------------------------------------------------------------- lainz · 2017-03-06 17:22 The solution was changing Length with UTF8Length of the unit LazUTF8. If there's a better way please comment. Also a question is if any other methods need to use UTF8 version of them. ---------------------------------------------------------------------- esvignolo · 2017-03-06 17:25 Thanks to @Lainz to clarify me. The .length property is in bytes, if u want know the length in char u must use UTF8Length (in LazUTF8 unit) Here is solved: 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, LConvEncoding, LazUTF8; type   { TForm1 }   TForm1 = class(TForm)    Edit1: TEdit;  Edit2: TEdit;    Label1: TLabel;    Label2: TLabel;    procedure Edit1Change(Sender: TObject);    procedure Edit2Change(Sender: TObject);    procedure FormShow(Sender: TObject);  private   public   end;  var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Edit1Change(Sender: TObject); begin   Label1.Caption:='Length: '+intToStr(UTF8Length(edit1.Text))+'  GuessEncoding: '+GuessEncoding(edit1.Text);end;  procedure TForm1.Edit2Change(Sender: TObject);begin    Label2.Caption:='Length: '+intToStr(UTF8Length(edit2.Text))+'  GuessEncoding: '+GuessEncoding(edit2.Text);end; procedure TForm1.FormShow(Sender: TObject);begin    Edit1Change(self);    Edit2Change(self);end; end.