如s:='abc'
想变成s:='cba'
因为字符串很长,将近1200个字符,所以无法每个字符转,有没有一次性的函数

解决方案 »

  1.   

    自己写一个吧
    function Convert_V(S :string ):string  ;
    var i : integer ;
    begin
      if length(trim(S))=0 then
      begin
        Result := S;
        Exit ;
      end ;
       Result := '' ;
      for  i :=  (length(s) ) downto 0 do
      begin
        Result := Result + s[i];
      end ;
    end ;
      

  2.   

    用for吧,传进来个s,传出去个反过来的sCString strTmp:="";
    ll:Integer;
    ll:=length(s)
    for i:=0 to ll-1 do
      begin
        strTmp := strTmp+s[ll-i-1];
      end;
    result := strTmp;
      

  3.   

    自己写一个吧
    function Convert_V(S :string ):string  ;
    var i : integer ;
    begin
      if length(trim(S))=0 then
      begin
        Result := S;
        Exit ;
      end ;
       Result := '' ;
      for  i :=  (length(s) ) downto 0 do
      begin
        Result := Result + s[i];
      end ;
    end ;
      

  4.   

    给你写了个API ReverseStr:
    procedure StrReverse(P: PChar);
    var
      E: PChar;
      c: Char;
    begin
      if StrLen(P) > 1 then
      begin
        E := P;
        Inc(E, StrLen(P) - 1);          // E -> last char in P
        repeat
          c := P^;                      // store beginning char in temp
          P^ := E^;                     // store end char in beginning
          E^ := c;                      // store temp char in end
          Inc(P);                       // increment beginning
          Dec(E);                       // decrement end
        until Abs(Integer(P) - Integer(E)) <= 1;
      end;
    end;function ReverseStr(const S: string): string;
    begin
      Result := S;
      StrReverse(PChar(Result));
    end;
      

  5.   

    我写的,效率不错.procedure ReverseStr(const s:string);
    var i,n:integer;iLen:integer;
    begin
     iLen:=Length(s)
     for i:=1 to iLen div 2 do
     begin
        n:=iLen-i;
        s[i]:=s[i] xor s[n];
        s[n]:=s[i] xor s[n];
        s[i]:=s[i] xor s[n];
     end;
    end;
      

  6.   

    只能自己写个转换函数了,好象没有自带API函数,SQL SERVER 里有个reverse可以转换
      

  7.   

    Eastunfail(浴血雏龙)==(恶鱼杀手) 寫的不能運行啊?誰再解釋一下?俺菜
      

  8.   

    反转字符串    
        
    function ReverseString1(const s: string): string;vari, len: Integer;beginlen := Length(s);SetLength(Result, len);for i := len downto 1 dobeginResult[len - i + 1] := s[i];end;end;function ReverseString2(const Str: string): string;// by Ido Kannervarch: Char;i, Size: Integer;beginResult := Str;Size := Length(Result);if (Size >= 2) then// 2 or more charsbegin// For 1 to middle of the stringfor i := 1 to (Size div 2) dobegin// Lets get the charecter of the current place in the stringch := Result[i];// Place the Current pos of the char// with the char of it's mirror place...Result[i] := Result[Size - (i - 1)];// In the mirror place we will put char of the// Original place... And we switched places !!!Result[Size - (i - 1)] := ch;endend;end; function ReverseString3(S: string): string;// by Rudy VelthuisvarP, Q: PChar;C: Char;beginResult := S;if Length(Result) = 0 then Exit;P := PChar(Result);Q := P + Length(Result) - 1;while P < Q dobeginC := P^;P^ := Q^;Q^ := C;Inc(P);Dec(Q);end;end;procedure ReverseString4(var S: string);// by Rudy VelthuisvarP, Q: PChar;C: Char;beginif Length(S) = 0 then Exit;P := PChar(S);Q := P + Length(S) - 1;while P < Q dobeginC := P^;P^ := Q^;Q^ := C;Inc(P);Dec(Q);end;end;
     
     
    ----From "Delphi tips"
      

  9.   

    呵呵,来晚了啊,给你一个好用的
    首部 function ReverseString(const AText: string): string; $[StrUtils.pas
    功能 返回字符串AText的反序
    说明 ReverseString('1234') = '4321'
    参考 function System.SetLength
    例子 Edit3.Text := ReverseString(Edit1.Text);
    就用这个函数,轻松搞顶~!
      

  10.   

    我的算法修改了(上次的是随手写的没有测试),可以用了。使用ReverseString需要分配额外的内存。如果你做的系统需要很高的效率,那么就用这个:
    procedure ReverseStr(var s:string);
    var i,iLen,n:integer;
    begin
        iLen:=length(s);
        for i:=1 to Trunc(iLen / 2) do
        begin
            n:=iLen-i+1;
            s[i]:=Char(Ord(s[i]) xor Ord(s[n]));
            s[n]:=Char(Ord(s[i]) xor Ord(s[n]));
            s[i]:=Char(Ord(s[i]) xor Ord(s[n]));
        end;
    end;