有關 unicode string function 的補強函數庫

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

有關 unicode string function 的補強函數庫

文章 tim »

有關 unicode string function 的補強函數庫

http://fundementals.sourceforge.net/cUnicode.html

例如使用 WidePos 就可以進行 Pos 的 widestring 版本. 相當值得參考的一篇文章.

代碼: 選擇全部

function WidePMatch(const M: WideString; const P: PWideChar): Boolean;
var I, L : Integer;
   Q, R : PWideChar;
begin
 L := Length(M);
 if L = 0 then
   begin
     Result := False;
     exit;
   end;
 R := Pointer(M);
 Q := P;
 For I := 1 to L do
   if R^ <> Q^ then
     begin
       Result := False;
       exit;
     end else
     begin
       Inc(R);
       Inc(Q);
     end;
 Result := True;
end;


function WidePos(const F: WideString; const S: WideString; const StartIndex: Integer=1): Integer;
var P : PWideChar;
   I, L : Integer;
begin
 L := Length(S);
 if (StartIndex > L) or (StartIndex < 1) then
   begin
     Result := 0;
     exit;
   end;
 P := Pointer(S);
 Inc(P, StartIndex - 1);
 For I := StartIndex to L do
   if WidePMatch(F, P) then
     begin
       Result := I;
       exit;
     end
   else
     Inc(P);
 Result := 0;
end; 
多多留言, 整理文章, 把經驗累積下來.....
回覆文章