Forum > Beginners

Character Conversions

(1/10) > >>

JLWest:
Trying to convert Non-ASCII words to ASCII words without success. Most of the words will be UTF8 but some of it is Greek, Arabic and who knows what. About 11 to 15 mill words. Some are already ASCII.

I dont expect anyone to write the code just give me an idea where to start.

I have read quite a bit on this but I don't understand how to implement it in code.



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TForm1.ToASCII(ASTRING : String) : String; Var AWord : AnsiString;  Begin  AWord : AString;    What has to go here to acheive this;    Result := AWord; end;

Handoko:
I think I can understand what you said. But can you please provide examples what are the inputs and the outputs. So I can work based on your examples.

winni:
Have a look at this dicussion:

https://forum.lazarus.freepascal.org/index.php/topic,45802.msg324361.html?PHPSESSID=4daqvc2e146snr2c9f5dd2trf4#msg324361

Winni

JLWest:

--- Quote from: Handoko on September 19, 2019, 08:30:20 pm ---I think I can understand what you said. But can you please provide examples what are the inputs and the outputs. So I can work based on your examples.

--- End quote ---

Input:                                            Output
Les Bruyères                                Les Bruyeres
Centre Médical Héliporté               Centre Medical Heliporte
Vésale Heliport
Saïss Airport
Fès-Boulemane
Léopold
Kédougou
Cesária
Évora
São
Ploče
Otočac
Čakovec
Almería
León
León
Logroño-Agoncillo
Suárez
Compiègne
Tréport
Périgueux
Targé
Châtellerault
Épernay
Pápa
Pécs-Pogány
Győr-Pér
Pér


Hope this answers your question. The list on the left is the who knows and the right are ASCII

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Les BruyèresCentre Médical Héliporté Vésale HeliportSaïss AirportFès-BoulemaneLéopold KédougouCesáriaÉvoraSão PločeOtočacČakovecAlmeríaLeón LeónLogroño-AgoncilloSuárezCompiègneTréportPérigueuxTargéChâtelleraultÉpernayPápaPécs-PogányGyőr-PérPér    

howardpc:
Try the following:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; {$mode objfpc}{$H+}{$IfDef windows}{$AppType console}{$EndIf}  uses   iconvenc, Types, LazUTF8; function ConvertToAscii(aUTF8Text: String): String;var  s, tmp: String;  p: PChar;  pEnd: PChar;  i, j: Integer;begin  Result := '';  p := PChar(aUTF8Text);  pEnd := p;  Inc(pEnd, Length(aUTF8Text));  repeat    i := UTF8CodepointSize(p);    case i of      1: Result += p^;      else        begin          SetLength(s, i);          for j := 1 to i do            begin              Inc(p, j-1);              s[j] := p^;            end;          Iconvert(s, tmp, 'UTF-8', 'ASCII//TRANSLIT');          Result += tmp[1];        end;    end;    Inc(p);  until p >= pEnd;end; var  strs: TStringDynArray;  s: String; begin  strs := TStringDynArray.Create('Les Bruyères', 'Centre Médical Héliporté',                                 'Vésale Heliport', 'Saïss Airport',                                 'Fès-Boulemane', 'Léopold', 'Kédougou',                                 'Cesária', 'Évora', 'São', 'Ploče', 'Otočac',                                 'Čakovec', 'Almería', 'León', 'León',                                 'Logroño-Agoncillo', 'Suárez', 'Compiègne',                                 'Tréport', 'Périgueux', 'Targé', 'Châtellerault',                                 'Épernay', 'Pápa', 'Pécs-Pogány', 'Győr-Pér', 'Pér');  for s in strs do    WriteLn(ConvertToAscii(s));  Readln;end.
It gives the following output on Linux (not tested on Windows):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Les BruyeresCentre Medical HeliporteVesale HeliportSaiss AirportFes-BoulemaneLeopoldKedougouCesariaEvoraSaoPloceOtocacCakovecAlmeriaLeonLeonLogrono-AgoncilloSuarezCompiegneTreportPerigueuxTargeChatelleraultEpernayPapaPecs-PoganyGyor-PerPer

Navigation

[0] Message Index

[#] Next page

Go to full version