我想把一个字符串从一个指定的字符截成两部分,比如asdgf,假如指定的字符是d的话,那么前一部分是as,后一部分就是gf,请问这个函数是什么?

解决方案 »

  1.   

    var I: integer;
        s: string;
    begin
      s := 'asdgf';
      i := pos('d', s);
      if i> 0 then
      begin
        showmessage(Copy(s, 1, i-1));
        showMessage(copy(s, i+1, 100));  end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    Const
      Splitor='.';//定义分隔符为 .
    Var
      aStr,s1,s2:String;
      atpos,SplitorLen:Integer;
    begin
    SplitorLen:=Length(Splitor);
    aStr:='中国.北京';
    atPos:=Pos(Splitor,aStr)-1;
    S1:=Copy(aStr,1,atPos);
    atPos:=Pos(Splitor,aStr)+SplitorLen;
    s2:=Copy(aStr,atPos,Length(aStr));
    ShowMessage('分隔为:'+#13+#13+s1+#13+#13+s2);
    end;
      

  3.   

    copy(a:string;i,j:integer)函数就可以的
      

  4.   

    可以用Copy函数来截取字符~~
      

  5.   

    你可以调用我写的过程: String_Divide_TwoPart(你要分解的串,,子串,前半串,后半串)
    procedure String_Divide_TwoPart(str:string;str1:string;var  firstPart:string;var      SecondPart);                                  
    var
      pos1:integer;
    begin
      pos1:=pos(str,str1);//子串d在总串的位置
      firstPart:=copy(str,1,pos1-1);
      SecondPart:=copy(str,pos1+length(str1));
    end;
      

  6.   

    主要是利用POS取得子串的位置,使用COPY来提取字符串
      

  7.   

    function SplitStrByFlag(s:string;Flag:string;Head:Bool):string;
    var
        iPos:integer;
    begin
        result:='';
        ipos:=Pos(flag,s);
        if iPos =0 then exit;    if Head then
            result:=Leftstr(s,iPos-1)
        else
            result:=midstr(s,iPos+1,1024);end;
      

  8.   

    copy('asdgf',1,pos('d','asdgf')-1)
    copy('asdgf',pos('d','asdgf')+1,length('asdgf'))哎,估计是拿不到分了
      

  9.   

    同意上面的.
    用copy,left,right都可以.
    left('asdgf',1,pos('d','asdgf')-1)
    left('asdgf',pos('d','asdgf')+1,length('asdgf'))
    right是一樣的
      

  10.   

    没有现成的函数,用 Pos, Copy 组合就可以实现
      

  11.   

    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
        k:string;
    begin
    for i:=1 to length(edit1.text) do
       begin
         if copy(edit1.text,i,1)<>'/' then
            k:=k+copy(edit1.text,i,1)
         else
          begin
           memo1.Lines.Add(k);
           k:='';
          end;
       end;
    end;