需要高手帮忙!!(关于转换)急急!! (50分)

T

ts007

Unregistered / Unconfirmed
GUEST, unregistred user!
form 上有一个memo,memo的内容是由特殊符号组成的文章

如: n"opD*>5{b$ {包括英文字符,数字和特殊符号}

能不能memo 中的字符转换成其他字符?

如 n"opD*>5{ 要转换成 1608;1567;1584;1573;1585;1576;1582;1580;1610;
////////////////////////////////////
或 把 1608;1567;1584;1573;1585;1576;1582;1580;1610;转换成 n"opD*>5{
///////////////////
转换对应表如下

原字符 目标

&amp
1575;
( 1577;
" 1567;
n 1608;
o 1584;
p 1573;
q 1609;
D 1585;
E 1586;
F 1570;
C 1583;
i 1606;
2 1578;
* 1576;
/ 1589;
> 1582;
5 1580;
9 1581;
w 1593;
s 1574;
{ 1610;
V 1602;
S 1601;
O 1594;
/ 1603;
Y 1590;
_ 1579;
e 1605;
l 1607;
b 1604;
$ 1571;
G 1587;
K 1588;
r 1572;
 
做个对照表,TStrings,里面存储对应编码,然后循环memo.lines,替换
 
to cnsandboy : 朋友能不能详细一点
需要代码!!
turan2003_27@hotmail.com
 
我有个苯方法
var
stringlist : tstrings;
s : string;
hjw : array[1..34] of string

先把MEMO 中的字符取出为S
stringlist := tstringlist.Create;
for i :=1 to length(s) do
begin
k := 0
for j := 0 to stringlist.Count-1 do
begin
if s='&'then stringlist.Strings[j]
then begin
hjw[k]:=stringlist.Strings[j];
k : =k + 1;
end


if s='('then stringlist.Strings[j]
then begin
hjw[k]:=stringlist.Strings[j];
k : =k + 1;
end

然后接着一个个判断

end;
end;
 
uses StrUtils;

CONST CHARCONVERT = '&,1575'+#13+'(,1577'+#13+'",1567'+#13+'n,1608'+#13+'o,1584'+#13+'p,1573'+#13+'q,1609'+#13+''+
'D,1585'+#13+'E,1586'+#13+'F,1570'+#13+'C,1583'+#13+'i,1606'+#13+'2,1578'+#13+'*,1576'+#13+'/,1589'+#13+'>,1582'+#13+''+
'5,1580'+#13+'9,1581'+#13+'w,1593'+#13+'s,1574'+#13+'{,1610'+#13+'V,1602'+#13+'S,1601'+#13+'O,1594'+#13+'/,1603'+#13+''+
'Y,1590'+#13+'_,1579'+#13+'e,1605'+#13+'l,1607'+#13+'b,1604'+#13+'$,1571'+#13+'G,1587'+#13+'K,1588'+#13+'r,1572'+#13;
function GetConvertCode(SourceCode: Char): string;
var
tmpSL:TStringList;
Index:Integer;
begin
tmpSL := TStringList.Create;
try
tmpSL.Text := CHARCONVERT;
tmpSL.Sort;
tmpSL.Find(SourceCode,Index);
if Index<>-1 then
begin
Result := tmpSL[Index];
tmpSL.Clear;
tmpSL.Text := AnsiReplaceText(Result,',',#13);
Result := tmpSL[1]+';';
end;
finally
tmpSL.Free;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
begin
for i := 1 to Length(memo1.Lines.Text) do
begin
Memo2.Lines.Text := Memo2.Lines.Text + GetConvertCode(Memo1.Lines.text);
end;

end;
 
代码写好了,TurnNumber是自己定义的函数
function TForm1.TurnNumber(C: Char): String;
begin
case C of
'&amp;' : Result:='1575';
'(' : Result:='1577';
'"' : Result:='1567';
'n' : Result:='1608';
'o' : Result:='1584';
'p' : Result:='1573';
'q' : Result:='1609';
'D' : Result:='1585';
'E' : Result:='1586';
'F' : Result:='1570';
'C' : Result:='1583';
'i' : Result:='1606';
'2' : Result:='1578';
'*' : Result:='1576';
'/' : Result:='1589';
'>' : Result:='1582';
'5' : Result:='1580';
'9' : Result:='1581';
'w' : Result:='1593';
's' : Result:='1574';
'{' : Result:='1610';
'V' : Result:='1602';
'S' : Result:='1601';
'O' : Result:='1594';
'/' : Result:='1603';
'Y' : Result:='1590';
'_' : Result:='1579';
'e' : Result:='1605';
'l' : Result:='1607';
'b' : Result:='1604';
'$' : Result:='1571';
'G' : Result:='1587';
'K' : Result:='1588';
'r' : Result:='1572';
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
Var
I,J: Integer;
begin
Edit1.Text:=TurnNumber(Memo1.Lines[0][1]);
for J:=0 to Memo1.Lines.Count-1 do
for I:=2 to Length(Memo1.Lines[J]) do
Edit1.Text:=Edit1.Text+';'+TurnNumber(Memo1.Lines[J]);
end;
 
to kirinma : 朋友 ,我没有用过 自己定义的函数
能不能帮我一个忙!!!!!!!
你的程序你调试过吗?
 
to cnsandboy: 朋友刚才你写的程序转能不能改称 , 能互相转换的程序?
比如: 把1608;1567;1584;1573;1585;1576;1582;1580;1610
能转换成 n"opD*>5{
或者 把 n"opD*>5{ 转换成 1608;1567;1584;1573;1585;1576;1582;1580;1610;
谢谢你的帮助!!!!!!!
 

Similar threads

顶部