How do I parse UTF8 strings?

uses LCLProc;
...
procedure IterateUTF8Characters(const AnUTF8String: string);
var
  p: PChar;
  unicode: Cardinal;
  CharLen: integer;
begin
  p:=PChar(AnUTF8String);
  repeat
    unicode:=UTF8CharacterToUnicode(p,CharLen);
    writeln('Unicode=',unicode);
    inc(p,CharLen);
  until (CharLen=0) or (unicode=0);
end;

uses
  ..., LCLProc;
 
...
 
for I := 1 to UTF8Length(S) do begin
  if (UTF8Copy(S, I, 1) = 'a') and (UTF8Copy(S, I, 1) = 'b') then go;
end;

use the utf8scanner:
http://wiki.lazarus.freepascal.org/Theodp

同步内容