字符串0123456789.(包括小数点“.”,数据类型为字符串)
要把每个数自动按下面的规则转换!请问应该怎么写?
0-30,00,
1-31,00,
2-32,00,
3-33,00,
4-34,00,
5-35,00,
6-36,00,
7-37,00,
8-38,00,
9-39,00,
,-30,00,
.-2e,00,
要把每个数自动按下面的规则转换!请问应该怎么写?
0-30,00,
1-31,00,
2-32,00,
3-33,00,
4-34,00,
5-35,00,
6-36,00,
7-37,00,
8-38,00,
9-39,00,
,-30,00,
.-2e,00,
begin
if str[i]=1 then
strresult:=strresult+'30,00,'
else if str[i]=2 then
...................
end;
length('123.3.3.123')
str: string;
str2: string;
i: integer;
begin str := '123.3.3.123';
str2 := '';
for i := 1 to length(str) do
begin
if str[i] = '0' then
str2 := str2 + '30,00,'
else if str[i] = '1' then
str2 := str2 + '31,00,'
else if str[i] = '2' then
str2 := str2 + '32,00,'
else if str[i] = '3' then
str2 := str2 + '33,00,'
else if str[i] = '4' then
str2 := str2 + '34,00,'
else if str[i] = '5' then
str2 := str2 + '35,00,'
else if str[i] = '6' then
str2 := str2 + '36,00,'
else if str[i] = '7' then
str2 := str2 + '37,00,'
else if str[i] = '8' then
str2 := str2 + '38,00,'
else if str[i] = '9' then
str2 := str2 + '39,00,'
else if str[i] = ',' then
str2 := str2 + '30,00,'
else if str[i] = '.' then
str2 := str2 + '2e,00,'
else
str2 := str2 + str[i];
end;
showmessage(str2);
end;
rs:='';
for i:=1 to length(str) do
begin
if str[i]='.' then
rs:=rs+'2e,00,'
else if str[i]=',' then
rs:=rs+'30,00,'
else if(str[i]>='0')and(str[i]<='9') then
rs:=rs+inttostr(ord(str[i]))+',00,';
end;
var
i: Integer;
tmp: String;
begin
Result := '';
for i := 1 to Length(value) do
begin
case value[i] of
'0': tmp := '30,00,';
'1': tmp := '31,00,';
'2': tmp := '32,00,';
'3': tmp := '33,00,';
'4': tmp := '34,00,';
'5': tmp := '35,00,';
'6': tmp := '36,00,';
'7': tmp := '37,00,';
'8': tmp := '38,00,';
'9': tmp := '39,00,';
',': tmp := '30,00,';
'.': tmp := '2e,00,';
end;
Result := Result + tmp;
end;
end;
str:='123.3.3.123';
rs:='';
for i:=1 to length(str) do
begin
if str[i]='.' then
rs:=rs+'2e,00,'
else if str[i]=',' then
rs:=rs+'30,00,'
else if(str[i]>='0')and(str[i]<='9') then
rs:=rs+inttohex(ord(str[i]),1)+',00,';
end;
var
i: Integer;
str: PChar;
begin
// ',' 转换按照'0'进行
str := PChar(StringReplace(src, ',', '0', [rfReplaceAll]));
result := '';
for i := 1 to length(src) do
result := result + Format( '%2x,00,', [Ord(str[i-1])] );
end;