我要获取字符串中左边,或右边的字符,可采用哪些函数?能否给出一些具体的用法?Thank you!

解决方案 »

  1.   

    copy(字符串,起始位置,长度)
      

  2.   

    uses StrUtils;LeftStr('Hello', 2)    // 'He'
    RightStr('Hello', 2)   // 'lo'
      

  3.   

    在uses单元中引用StrUtils;LeftStr('abc',1);//返回'a'
    RightStr('abc',1);//返回'c'
      

  4.   

    由于我的程序可能较大,哪种方法耗资源较少?我只取左边
    A:copy(字符串,起始位置,长度)
    B:LeftStr
      

  5.   

    那就直接用Copy吧,少一层调用。LeftStr和RightStr都是用Copy实现的:
    { StrUtils.pas }
    function LeftStr(const AText: string; const ACount: Integer): string;
    begin
      Result := Copy(AText, 1, ACount);
    end;function RightStr(const AText: string; const ACount: Integer): string;
    begin
      Result := Copy(AText, Length(AText) + 1 - ACount, ACount);
    end;
      

  6.   

    uses StrUtils;左LeftStr
    右RightStr
    中间的MidStrCopy也OK,但没那么简单