Recent

Author Topic: I have difficulty displaying correct accented letter values  (Read 446 times)

aacs

  • New member
  • *
  • Posts: 7
I have difficulty displaying correct accented letter values
« on: February 13, 2021, 06:15:52 am »
 :) I would be very grateful if you could help me!

I need  to show the values of the accented letters as well
thanks!

function valor(Str:String):String;
const
Lin1:String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÆÁÂÅÃÄáâæàåãäÉÊÈÍÎÌÏÇÓÔÒØÖÞÚÛÙÜæáâåãäáâæàåãäéêèíîìïçóôòøöþúûùü';
Lin2:String = '123456789123456789123456781234567891234567891234567811111111111115559999366666633331111111111111555999936666663333';

var
x,y:integer;
begin
   Result:='';
   for y:=1 to Length(Str) do
     begin
       x:=0;
       repeat x:=x+1;
       until Str[y]=Lin1
  • ;

       Result:=Result+Lin2
  • ;

     end;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
   Memo1.clear;
   Memo1.text:=(valor(Edit1.Text));
end;
« Last Edit: February 13, 2021, 06:22:24 am by aacs »

speter

  • Sr. Member
  • ****
  • Posts: 349
Re: I have difficulty displaying correct accented letter values
« Reply #1 on: February 13, 2021, 08:37:49 am »
Please consider enclosing your code within [code]...[/code] tags (the # symbol in the forum's "post" page.
« Last Edit: February 13, 2021, 09:44:29 am by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

paweld

  • Hero Member
  • *****
  • Posts: 1003
Re: I have difficulty displaying correct accented letter values
« Reply #2 on: February 13, 2021, 08:48:16 am »
Add unit LazUTF8 to uses section and:
  • Length(Str) replace to UTF8Length(Str)
  • Str[y] replace to UTF8Copy(Str, y, 1)
eg.
Code: Pascal  [Select][+][-]
  1. uses
  2.   LazUTF8;
  3.  
  4. function valor(Str:String):String;
  5. const
  6.   Lin1: String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÆÁÂÅÃÄáâæàåãäÉÊÈÍÎÌÏÇÓÔÒØÖÞÚÛÙÜæáâåãäáâæàåãäéêèíîìïçóôòøöþúûùü';
  7.   Lin2: String = '123456789123456789123456781234567891234567891234567811111111111115559999366666633331111111111111555999936666663333';
  8. var
  9.   x, y:integer;
  10. begin
  11.    Result:='';
  12.    for y:=1 to UTF8Length(Str) do
  13.    begin
  14.      x := UTF8Pos(UTF8Copy(Str, y, 1), Lin1);
  15.      if x > 0 then
  16.        Result:=Result+UTF8Copy(Lin2, x, 1);
  17.    end;
  18. end;
  19.  
  20. procedure TForm1.Edit1Change(Sender: TObject);
  21. begin
  22.    Memo1.clear;
  23.    Memo1.text:=(valor(Edit1.Text));
  24. end;    
« Last Edit: February 13, 2021, 08:53:23 am by paweld »
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018