我想得到一个字符串中第一个“|”前的所有字符,什么函数可以得到?
并且取得“|”前的字符串后,其后面的字符串仍旧要保留下来!
因为后面还有“|”符号,仍旧要要切割的字符!
谢谢!

解决方案 »

  1.   

    Pos 与 copy
    考虑考虑!
      

  2.   

    var
      Index :integer;
      str1 :string ;
    begin
      Index := pos('|', yourstr)  ;
      str1 := Copy(yourstr, 1, Index - 1);
      delete(yourstr, 1, Index);
    end ;
      

  3.   

    unit ToolsUnit;interface  function StrLeft(const mStr: String; mDelimiter: String): String;
      function ListCount(mList: String; mDelimiter: String): Integer;
      function ListValue(mList: String; mIndex: Integer; mDelimiter: String =','): String;implementation//============================  StrLeft  =====================================//
    function StrLeft(const mStr: string; mDelimiter: string): string;
    { 返回左分隔字符串 }
    begin
      Result := Copy(mStr, 1, Pos(mDelimiter, mStr) - 1);
    end;//===========================  ListCount =====================================//
    function ListCount(mList: string; mDelimiter: string ): Integer;
    { 返回列表数 }
    var
      I, L: Integer;
      mListC:String;
    begin
      Result := 0;
      if mList = '' then Exit;
      mListC := mList;
      L := Length(mList);
      I := Pos(mDelimiter , mList);
      while I > 0 do begin
        mList := Copy(mList , I + Length(mDelimiter), L);
        I := Pos(mDelimiter , mList);
        Inc(Result);
      end;
      Inc(Result);
      if PChar(mListC)[0] = mDelimiter then
        Result := Result - 1;
      if PChar(mListc)[Length(mListc)-1] = mDelimiter then
        Result := Result - 1;
    end;//=============================  ListValue  ==================================//
    function ListValue(mList: string; mIndex: Integer; mDelimiter: string = ','): string;
    { 返回列表指定位置的元素 }
    var
      I, L, K: Integer;
    begin
      if Pchar(mList)[Length(mList)-1] <> mDelimiter then
        mList:=mList + mDelimiter;
      L := Length(mList);
      I := Pos(mDelimiter, mList);
      K := 0;
      Result := '';
      while (I > 0) and (K <> mIndex) do begin
        mList := Copy(mList, I + Length(mDelimiter), L);
        I := Pos(mDelimiter, mList);
        Inc(K);
      end;
      if K = mIndex then
        Result := StrLeft(mList + mDelimiter, mDelimiter);
    end;end.想怎么用就怎么用
      

  4.   

    copy(str,0,pos('|',str)-1)
    知道了否?
      

  5.   

    delete(str, 1, Index);
    报错:
    Incompatible types:'integer' and 'String'
    但我已经定义了:
    Index :integer;
    str:string ; 为什么会这样?
      

  6.   

    var
      Index :integer;
      str, str1 :string ;
    begin
      str := 'asgsd|slgj23o|ss' ;
      Index := pos('|', str)  ;
      str1 := Copy(str, 1, Index - 1);
      System.delete(str, 1, Index);  //应该可能和别的对象的DELETE方法冲突
      ShowMessage(Str1) ;
      ShowMessage(str) ;
    end ;
      

  7.   

    Result := GetShortHint(str);
      

  8.   

    得到后面的用:
    Result := GetLongHint(Str);
    这两个函数配合用可以得到用管道符分隔的字符串元素
      

  9.   

    zfmich:
    System.delete(str, 1, Index);  //应该可能和别的对象的DELETE方法冲突
    这里的system指什么?楼上的:
    你是指getlonghint函数和哪个函数一起用?