字符串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,

解决方案 »

  1.   

    就是如果有数  123.3.3.123要输出结果为  31,00,32,00,33,00,2e,00,33,00,2e,00,33,00,2e,00,31,00,32,00,33,00,
      

  2.   

    for i:=0 to lenth(123.3.3.123)
    begin
       if str[i]=1 then
          strresult:=strresult+'30,00,'
       else if str[i]=2 then
          ...................
    end;
      

  3.   

    楼上的方法正确!
    length('123.3.3.123')
      

  4.   

    var
        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;
      

  5.   

    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+inttostr(ord(str[i]))+',00,';
    end;
      

  6.   

    function TForm1.translate(const value: String): String;
    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;
      

  7.   

    不好意思打错了,应该将inttostr改成inttohex;如下:
    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;
      

  8.   

    function TForm1.StrChr2Asc(src: String): String;
    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;