02  [root]取为0202与[root]中间为两空格

解决方案 »

  1.   

    Copy(字符串, 开始位置, 长度);
      

  2.   

    ShowMessage(copy('02  [root]',0,2));
      

  3.   

    02  [root]取为02
    ‘02’这个串为不固定的宽度
      

  4.   

    function PickStr(Value: string): string;
    begin
      result:= Trim(Copy(Value, 1, Pos('[root]', Value) - 1));
    end;
      

  5.   

    哦哦。一次把问题说清楚不行啊?
    这个不定,那个不定,总得有点规律吧?没有规律是做不了的。
    只要有规律,用phaler(phaler) 的方法就基本可以搞定了。
      

  6.   

    //把phaler(phaler)的该一下就可以了
    function PickStr(Value: string): string;
    begin
      result:= Trim(Copy(Value, 1, Pos('[', Value) - 1));
    end;
      

  7.   

    var I: integer;
        str: string;
        index: integer;        
    begin
      str := 02  [root];
      for I := 0 to length(str)-1 do 
      begin
        if (str[I] = ' ') and (index = 0) then
        begin
           index := I;  
        end
        else if (str[I] = ' ') and (index > 0) then
        begin
          exit;
        end;
      end;  result := copy(str,0,index - 1 );   //结果;
    end;