* * *

Author Topic: Where is the error in this function?  (Read 5590 times)


  • Sr. Member
  • ****
  • Posts: 421
Re: Where is the error in this function?
« Reply #15 on: March 11, 2018, 04:37:01 pm »
Try this:

Code: [Select]
function RemoveDiacritics(S :utf8string):utf8string;
// It should work for several languages
// Portuguese, Spanish and Italian, maybe for French, German and more
  AccentedChars :array[0..53] of utf8string = ('á','à','ã','â','ä','é','è','ê','ë','í','ì','ï','î','ó','ò','õ','ô','ö','ø','ú','ù','ü','û','ç','ñ','ÿ','ý',
  NormalChars   :array[0..53] of utf8string = ('a','a','a','a','a','e','e','e','e','i','i','i','i','o','o','o','o','oe','o','u','u','u','u','c','n','y','y',
  i, j :integer;
  Result := S;
  for i := 0 to High(AccentedChars) do
    Result := StringReplace(Result, AccentedChars[i], NormalChars[i], [rfReplaceAll]);

Hello. This code doesn't work . I have used a project from this message http://forum.lazarus.freepascal.org/index.php/topic,15576.msg83821.html#msg83821

I have attached images showing how arrays look like in memory. I think the problem is that the characters  with diacritics in AccentedChars are written as 4 bytes. While the string from the edit contains 2 bytes.

Suggestion from here  helps, making first array consisting of 2-byte chars (each array element occupies  16 bytes ).
« Last Edit: March 11, 2018, 05:24:51 pm by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)



Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus