delphi 如何获取edit的text中的每个汉字首字母呢

delphi 如何获取edit的text中的每个汉字首字母呢,第1张

碰巧我有这么一个函数

有点长,,不过,绝对能用

const py: array[216247] of string = (

{216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + 'QMBSGZSCYJSYYZPG' +

{216}'KBZGYCYWYKGKLJSW' + 'KPJQHYZWDDZLSGMR' + 'YPYWWCCKZNKYDG',

{217}'TTNJJEYKKZYTCJNM' + 'CYLQLYPYQFQRPZSL' + 'WBTGKJFYXJWZLTBN' +

{217}'CXJJJJZXDTTSQZYC' + 'DXXHGCKBPHFFSSYY' + 'BGMXLPBYLLLHLX',

{218}'SPZMYJHSOJNGHDZQ' + 'YKLGJHXGQZHXQGKE' + 'ZZWYSCSCJXYEYXAD' +

{218}'ZPMDSSMZJZQJYZCD' + 'JEWQJBDZBXGZNZCP' + 'WHKXHQKMWFBPBY',

{219}'DTJZZKQHYLYGXFPT' + 'YJYYZPSZLFCHMQSH' + 'GMXXSXJJSDCSBBQB' +

{219}'EFSJYHXWGZKPYLQB' + 'GLDLCCTNMAYDDKSS' + 'NGYCSGXLYZAYBN',

{220}'PTSDKDYLHGYMYLCX' + 'PYCJNDQJWXQXFYYF' + 'JLEJBZRXCCQWQQSB' +

{220}'ZKYMGPLBMJRQCFLN' + 'YMYQMSQYRBCJTHZT' + 'QFRXQHXMJJCJLX',

{221}'QGJMSHZKBSWYEMYL' + 'TXFSYDSGLYCJQXSJ' + 'NQBSCTYHBFTDCYZD' +

{221}'JWYGHQFRXWCKQKXE' + 'BPTLPXJZSRMEBWHJ' + 'LBJSLYYSMDXLCL',

{222}'QKXLHXJRZJMFQHXH' + 'WYWSBHTRXXGLHQHF' + 'NMCYKLDYXZPWLGGS' +

{222}'MTCFPAJJZYLJTYAN' + 'JGBJPLQGDZYQYAXB' + 'KYSECJSZNSLYZH',

{223}'ZXLZCGHPXZHZNYTD' + 'SBCJKDLZAYFMYDLE' + 'BBGQYZKXGLDNDNYS' +

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JHXPDHYJY' + 'BZGDLJCSEZGXLBLH' + 'YXTWMABCHECMWYJY' +

{240}'ZLLJJYHLGBDJLSLY' + 'GKDZPZXJYYZLWCXS' + 'ZFGWYYDLYHCLJS',

{241}'CMBJHBLYZLYCBLYD' + 'PDQYSXQZBYTDKYYJ' + 'YYCNRJMPDJGKLCLJ' +

{241}'BCTBJDDBBLBLCZQR' + 'PPXJCGLZCSHLTOLJ' + 'NMDDDLNGKAQHQH',

{242}'JHYKHEZNMSHRP QQ' + 'JCHGMFPRXHJGDYCH' + 'GHLYRZQLCYQJNZSQ' +

{242}'TKQJYMSZSWLCFQQQ' + 'XYFGGYPTQWLMCRNF' + 'KKFSYYLQBMQAMM',

{243}'MYXCTPSHCPTXXZZS' + 'MPHPSHMCLMLDQFYQ' + 'XSZYJDJJZZHQPDSZ' +

{243}'GLSTJBCKBXYQZJSG' + 'PSXQZQZRQTBDKYXZ' + 'KHHGFLBCSMDLDG',

{244}'DZDBLZYYCXNNCSYB' + 'ZBFGLZZXSWMSCCMQ' + 'NJQSBDQSJTXXMBLT' +

{244}'XZCLZSHZCXRQJGJY' + 'LXZFJPHYXZQQYDFQ' + 'JJLZZNZJCDGZYG',

{245}'CTXMZYSCTLKPHTXH' + 'TLBJXJLXSCDQXCBB' + 'TJFQZFSLTJBTKQBX' +

{245}'XJJLJCHCZDBZJDCZ' + 'JDCPRNPQCJPFCZLC' + 'LZXBDMXMPHJSGZ',

{246}'GSZZQLYLWTJPFSYA' + 'SMCJBTZYYCWMYTCS' + 'JJLQCQLWZMALBXYF' +

{246}'BPNLSFHTGJWEJJXX' + 'GLLJSTGSHJQLZFKC' + 'GNNDSZFDEQFHBS',

{247}'AQTGYLBXMMYGSZLD' + 'YDQMJJRGBJTKGDHG' + 'KBLQKBDMBYLXWCXY' +

{247}'TTYBKMRTJZXQJBHL' + 'MHMJJZMQASLDCYXY' + 'QDLQCAFYWYXQHZ'

);

function ChnPy(Value: array of char): Char;

begin

Result := #0;

case Byte(Value[0]) of

176:

case Byte(Value[1]) of

161196: Result := 'A';

197254: Result := 'B';

end; {case}

177:

Result := 'B';

178:

case Byte(Value[1]) of

161192: Result := 'B';

193205: Result := 'C';

206: Result := 'S'; //参

207254: Result := 'C';

end; {case}

179:

Result := 'C';

180:

case Byte(Value[1]) of

161237: Result := 'C';

238254: Result := 'D';

end; {case}

181:

Result := 'D';

182:

case Byte(Value[1]) of

161233: Result := 'D';

234254: Result := 'E';

end; {case}

183:

case Byte(Value[1]) of

161: Result := 'E';

162254: Result := 'F';

end; {case}

184:

case Byte(Value[1]) of

161192: Result := 'F';

193254: Result := 'G';

end; {case}

185:

case Byte(Value[1]) of

161253: Result := 'G';

254: Result := 'H';

end; {case}

186:

Result := 'H';

187:

case Byte(Value[1]) of

161246: Result := 'H';

247254: Result := 'J';

end; {case}

188190:

Result := 'J';

191:

case Byte(Value[1]) of

161165: Result := 'J';

166254: Result := 'K';

end; {case}

192:

case Byte(Value[1]) of

161171: Result := 'K';

172254: Result := 'L';

end; {case}

193:

Result := 'L';

194:

case Byte(Value[1]) of

161231: Result := 'L';

232254: Result := 'M';

end; {case}

195:

Result := 'M';

196:

case Byte(Value[1]) of

161194: Result := 'M';

195254: Result := 'N';

end; {case}

197:

case Byte(Value[1]) of

161181: Result := 'N';

182189: Result := 'O';

190254: Result := 'P';

end; {case}

198:

case Byte(Value[1]) of

161217: Result := 'P';

218254: Result := 'Q';

end; {case}

199:

Result := 'Q';

200:

case Byte(Value[1]) of

161186: Result := 'Q';

187245: Result := 'R';

246254: Result := 'S';

end; {case}

201202:

Result := 'S';

203:

case Byte(Value[1]) of

161249: Result := 'S';

250254: Result := 'T';

end; {case}

204:

Result := 'T';

205:

case Byte(Value[1]) of

161217: Result := 'T';

218254: Result := 'W';

end; {case}

206:

case Byte(Value[1]) of

161243: Result := 'W';

244254: Result := 'X';

end; {case}

207208:

Result := 'X';

209:

case Byte(Value[1]) of

161184: Result := 'X';

185254: Result := 'Y';

end; {case}

210211:

Result := 'Y';

212:

case Byte(Value[1]) of

161208: Result := 'Y';

209254: Result := 'Z';

end; {case}

213215:

Result := 'Z';

216247:

Result := py[Byte(Value[0])][Byte(Value[1]) - 160];

end; {case}

end;

function TitemMagChnToPY(Value: string): string;

var

I, L: Integer;

C: array[01] of char;

R: Char;

begin

Result := '';

L := Length(Value);

I := 1;

while I <= (L - 1) do

begin

if Value[I] < #160 then

begin

Result := Result + Value[I];

Inc(I);

end

else

begin

C[0] := Value[I];

C[1] := Value[I + 1];

R := ChnPY(C);

if r <> #0 then

Result := Result + R;

Inc(I, 2);

end;

end;

if I = L then

Result := Result + Value[L];

end;

使用一个memo控件 可以轻松的完成读文本文件功能 memoloadfromfile('文件名'); memolines[n]text 简单吧 查看更多答案>>

用正则表达式,快捷高效。

uses TRegExpEx;(自己找,万一的Delphi博客上有介绍)

然后按照这个模式构造正则表达式:

/123()89/

把Subject设为123456789,然后Match,在Matches[1]里面就是结果

//显示找到的第一个var reg: TPerlRegEx;begin reg := TPerlRegExCreate(nil); regSubject := 'CodeGear Delphi 2007 for Win32'; regRegEx := '\d'; if regMatch then ShowMessage(regMatchedExpression) //2 else ShowMessage('没找到'); FreeAndNil(reg);end;

function GetPYIndexChar( 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';

$D1B9$D4D0 : result := 'Y';

$D4D1$D7F9 : result := 'Z';

else

result := char(0);

end;

end;

以下是我的原码100%可以

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Edit1: TEdit;

Edit2: TEdit;

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

function GetPYIndexChar( hzchar:string):char;

var

Form1: TForm1;

implementation

{$R dfm}

function GetPYIndexChar( 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';

$D1B9$D4D0 : result := 'Y';

$D4D1$D7F9 : result := 'Z';

else

result := char(0);

end;

end;

procedure TForm1Button1Click(Sender: TObject);

begin

edit2Text:=GetPYIndexChar(edit1Text);

end;

end

procedure TForm1Button1Click(Sender: TObject);

var

ansiStr:AnsiString;

i,iLen: Integer;

begin

ansistr:=Edit1Text;

iLen:=Length(ansistr);

for i:=1 to iLen do

begin

if (ByteType(ansistr,i)=mbSingleByte) then

Memo1LinesAdd(ansistr[i]+' 是英文字符,占 1 字节。')

else if (ByteType(ansistr,i)=mbLeadByte) then

continue

else if (ByteType(ansistr,i)=mbTrailByte) then

Memo1LinesAdd(ansistr[i-1]+ansistr[i]+' 是全角字符,占 2 字节。')

else

Memo1LinesAdd(ansistr[i]+' 是其它字符。');

end;

end;

以上就是关于delphi 如何获取edit的text中的每个汉字首字母呢全部的内容,包括:delphi 如何获取edit的text中的每个汉字首字母呢、请问在delphi中如何读取文本文件中的数据、Delphi 获取两字符串之间的内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9430033.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存