字符串形式为:/*/*/*/,如何才能取得中间的*哪?*表示字符串     取得*之后,赋值给不同的变量。这样的语句该如何写哪?    谢了,:)

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        i : Integer;
        s : string;
    begin
        with TStringList.Create do
        begin
            s := '/33/"321 424"/24234234/';
            Delimiter :='/';
            DelimitedText := Copy(s,2,Length(s)-2);
            for i:=0 to Count-1 do
            begin
                if Strings[i]<>'' then
                ShowMessage(Strings[i]);
            end;
        end;
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        i : Integer;
        s : string;
    begin
        with TStringList.Create do
        begin
            s := '/33/"321 424"/24234234/';
            Delimiter :='/';
            DelimitedText := Copy(s,2,Length(s)-2);
            for i:=0 to Count-1 do
            begin
                if Strings[i]<>'' then
                ShowMessage(Strings[i]);
            end;
            free;
        end;
    end;
      

  3.   

    那就不能用上面的方法,得遍历一遍
    procedure TForm1.Button1Click(Sender: TObject);
    var
        s,sTemp : string;
        i : Integer;
    begin
        sTemp := '';
        s := '/33/321 424/2423'#10'4234/';
        for i:=2 to Length(s) do
        begin
            if s[i]='/' then
            begin
                ShowMessage(sTemp);
                sTemp :='';
            end
            else
                sTemp := sTemp+s[i];
        end;
    end;
      

  4.   

    通常可以分步完成
    设s0:='/abcd/efghij/klmop';1.去掉s0的第1个'/':
      s1:=copy(s0,2,length(s)-1);
      则s1='abcd/efghij/klmop';2.查出s0第2个'/'的位置, 也就是s1中第1个'/'的位置:
      p:=pos('/',s1);
      则 p=5;3.求s1中/后面的子串:
     s2:=copy(s1,p,length(s1)-p);
      则s2='efghij/klmop';4.查出s0第3个'/'的位置, 也就是s2中'/'的位置:
      p:=pos('/',s2);
      则p=7;5.求s3:=copy(s2,1,p-1);
      则s3就是结果efghij了.
      

  5.   

    /**/
    Function FillAStringList(Str : String; SL : TStrings):Boolean
    Var
     ret : Integer;
     tmp_str : String;
    Begin
     ret := Pos('/',Str);
     While ret > 0 do 
      Begin
        if ret = 1 then 
          str := Copy(str,ret+1,MaxInt);
        else
          Begin
          tmp_str := Copy(str,1,ret-1);
          SL.add(tmp_str);      
          end
      ret := Pos('/',Str);
      end;
      Result := True;
    end;//没测试
      

  6.   

    zzwu(未名) ( ) 信誉:104  2006-04-10 17:35:00  得分: 0  
     
     
       字符串中是不带换行的。  
     
    因为我是用MEMO插入的数据,不可能不带有换行,而且,必须有换行的
      

  7.   

    我写的函数,你试试好用不
    //返回substr在sousestr中第index次出现的位置
    function PosEx(subStr:string;SouseStr:string;Index:integer):integer;
    var
      i:integer;
      iPos:integer;
      AStr:string;
    begin
      AStr := SouseStr;
      result := 0;
      for i := 1 to Index do
      begin
        iPos := Pos(subStr,AStr);
        if iPos = 0 then exit;
        if i = Index then
        begin
          result := length(SouseStr) - length(AStr) + iPos;
          exit;
        end;
        System.Delete(AStr,1,iPos + length(subStr) - 1);
      end;
    end;