在DELPHI中,用什么函数取得一个字符串中左边或右边指定个数的字符?

解决方案 »

  1.   

    f:=copy(f,4,5);
    4:表示从第四个开始
    5:表示取5个
      

  2.   

    uses StrUtilsLeftStr/RightStrfunction 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;
      

  3.   

    uses  StrUtils单元 leftstr('ssss',3); //左边3位
     midstr('aaaaaaa',4,2);//第4个开始的2位。
     rightstr('sssss',2);//右边2位.
      

  4.   

    function GetString(SourceString:String;CutType,Count:Integer):String;
    var
      len:Integer;
    begin
      len := Length(SourceString);
      case CutType of
        0://从左边
        begin
          Result := Copy(SourceString,1,Count);
        end;
        1://
        begin
          if Count < len then
          begin
            Result := Copy(SourceString,len-Count+1,Count);
          end
          else
          begin
            Result := SourceString;
          end;
        end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      //从左边
      Self.Caption :=  GetString(Edit1.Text,0,5);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      //从右边
      Self.Caption := GetString(Edit1.Text,1,5);
    end;
      

  5.   

    copy 函数了,
    POS函数定位
      

  6.   

    StrUtils单元中
     leftstr()
      midstr()
      rightstr()
      

  7.   

    同意楼上,还是LeftStr()和RightStr()比较符合问题。