delphi 字串 生成拼音碼

2021-04-23 21:01:27 字數 1454 閱讀 2084

//--- 獲取拼音碼函式

function getpy(hzchar:string):char;

begin

case word(hzchar[1])shl 8+word(hzchar[2]) of

$b0a1..$b0c4:result:='a';

$b0c5..$b2c0:result:='b';

$b2c1..$b4ed:result:='c';

$b4ee..$b6e9:result:='d';

$b6ea..$b7a1:result:='e';

$b7a2..$b8c0:result:='f';

$b8c1..$b9fd:result:='g';

$b9fe..$bbf6:result:='h';

$bbf7..$bfa5:result:='j';

$bfa6..$c0ab:result:='k';

$c0ac..$c2e7:result:='l';

$c2e8..$c4c2:result:='m';

$c4c3..$c5b5:result:='n';

$c5b6..$c5bd:result:='o';

$c5be..$c6d9:result:='p';

$c6da..$c8ba:result:='q';

$c8bb..$c8f5:result:='r';

$c8f6..$cbf9:result:='s';

$cbfa..$cdd9:result:='t';

$cdda..$cef3:result:='w';

$cef4..$d188:result:='x';

$d189..$d4d0:result:='y';

$d4d1..$d7f9:result:='z';

else

result:=char(32);

end;

end;

//  以下** 呼叫getpy() 函式

//  edit_mc是輸入框

//  實現效果: --------  輸入: 中國asdw123廠 --------生成編碼: zgasdw12c

spbm:='';

i:=1;

while i<=length(edit_mc.text) do

begin

if bytetype(edit_mc.text,i) = mbsinglebyte then

//單位元組,不是漢字位元組

spbm:=spbm+copy(edit_mc.text,i,1)

else   //是漢字,擷取2個位元組取其拼音碼

begin

hz:=copy(edit_mc.text,i,2);

spbm:=spbm+getpy(hz);

i:=i+1;

end;

i:=i+1;

end;

showmessage(spbm);

拼音碼表的生成

拼音碼表的生成 啟動輸入法生成器在逆轉換選項卡中裝入window的拼音輸入法並將其儲存為文 本檔案 winpy.txt 備用。下面的 將拼音碼表檔案 文字 裝入到陣列 pymb中,結構為 拼音,漢字.碼表轉換時間較長,應轉換後另行儲存 filename pymb.txt if file exists...

Delphi 字串操作

常忘記,在此做筆記。這幾個函式都包含在strutils中,所以需要uses strutils 假設字串是 dstr delphi is the best 那麼 leftstr dstr,5 delph midstr dstr,6,7 i is th rightstr dstr,6 e best fu...

Delphi字串處理

悲催啊,使用了這麼久的delphi,還是沒有理解字串。今天看了一篇文章稍有理解。1.段字串shortstring。短字串的管理師這樣的,類似陣列 0處儲存字串的長度,從1處開始了內容,shortstring的總長度是256,因此,實際的內容長度只能為255,並且內容結束沒有結束字元,即不是以 0結尾...