有一字符串'__i will love__you more than that'
如何从其中提取每一个单词并放在一个数组中(其中_为空格)

解决方案 »

  1.   

    你试试下面的吧,我随便写的
    s:=trim('__i will love__you more than that')for i:=0 to length(s)-1 do
    begin
      if s[i]<>' ' then
        s1:=s1+s[i];
      if (s[i]=' ') and (s1<>'') then
        begin
          a[j]:=s1;
          inc(j);
          s1:='';
        end;
    end;
      

  2.   

    测试通过!procedure TForm1.Button1Click(Sender: TObject);
    var
      s: string;
      i: integer;
      StrList: TStringList;
      tempi: integer;
    begin
      Strlist:=TStringList.Create;
      StrList:=TStringList.Create;
      S := '__i will love__you more than that';
      tempi:=0;  for i:=0 to Length(s) -1 do
        if  not (S[i] in ['a'..'z' ,'A'..'Z']) then
        begin
          StrList.Add(Copy(s,tempi,i-tempi));
          tempi:=i;
        end;  ShowMessage(StrList.Text);end;