首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么集合成一行字符串

2012-10-21 
如何集合成一行字符串?以为起始符号,以为结束符号内容情况如下:------------------------------第100名

如何集合成一行字符串?
以<为起始符号,以>为结束符号
内容情况如下:
------------------------------

<
第100



<
第101



...

------------------------------
希望得到结果如下:
------------------------------
第100名

第101名

...


请大牛们帮帮忙,谢谢!!

[解决办法]

Delphi(Pascal) code
源数据放在Memo1中,结果放在Memo2中procedure TForm1.Button1Click(Sender: TObject);var  i:integer;  TmpStr,str:string;begin  for i:=0 to Memo1.Lines.Count-1 do  begin    str:= Memo1.Lines.Strings[i];    if str='<' then       TmpStr:=''    else if str='>' then       Memo2.Lines.Add(TmpStr)    else if str<>'' then       TmpStr:=TmpStr + str;  end;end;
[解决办法]
Delphi(Pascal) code
var  Sour , Dest : WideString;  PSour , PDest : PWideChar;  i , nSize : integer;  bKey , bText : Boolean;begin  //源内容装入到Memo1中  Sour := Trim(Memo1.Lines.Text);  SetLength(Dest , Length(Sour)*2);  PSour := Pointer(Sour);  PDest := Pointer(Dest);  bKey := False;  bText := False;  nSize := 0;  for i:=1 to Length(Sour) do begin    Case PSour^ of      #13,#10,#9,' ':;      '<' : begin bKey := True; bText := False;end;      '>' :        if bKey and bText then begin          PDest^ := #13;          inc(PDest);          PDest^ := #10;          inc(PDest);          inc(nSize,2);          bKey := False;        end;      else begin        if bKey then begin          PDest^ := PSour^;          inc(PDest);          inc(nSize);          bText := True;        end;      end;    end;    inc(PSour);  end;  //输出到Memo2中  Memo2.Text := Copy(Dest , 1 , nSize);end;
[解决办法]
Delphi(Pascal) code
procedure GetMatchResult(s:TStrings);var i:integer;begin  for i:=s.Count-1 downto 0 do begin    if (Length(Trim(s[i]))<3)or(Trim(s[i])='RING') then s.Delete(i)    else if s[i][1]='<' then      s[i]:=copy(s[i],2,length(s[i]));    if pos('=',s[i])>0 then      s[i]:=copy(s[i],1,pos('=',s[i])-1);    if pos('>',s[i])>0 then      s[i]:=copy(s[i],1,pos('>',s[i])-1);    s[i]:=Trim(s[i]);  end;end;procedure TForm1.Button1Click(Sender: TObject);begin  GetMatchResult(memo1.Lines);end; 

热点排行