讨论一下 在文章中选取文字的方法 (选取某段文字,选取特定的部分)(50分)

B

bborn

Unregistered / Unconfirmed
GUEST, unregistred user!
在一段文字中选取某个字段的文字<br>选取某个符号前的文字<br>选取某个符号中的文字<br>选取某行的文字<br>都有什么办法?<br>
 
如果是 TMemo 中应该比较方便的。
 
不讨论控件吧<br>我想主要是api是使用
 
各种文档的结构和类型不一样,如何做阿?应该 API 也无能为力。
 
就说一般的文档<br>假如就说是一封电子邮件的源代码
 
电子邮件的源代码有 HTML格式的。
 
算了 &nbsp;没有那么多事了只是举个例子而已<br>就这了<br>Return-Path: &lt;billing-4655@eachnet.com&gt;<br>Delivered-To: bborn@sina.com<br>Received: (qmail 22450 invoked from network); 2 Jul 2002 13:59:27 -0000<br>Received: from unknown (HELO mx1.eachnet.com) (61.129.69.105)<br>&nbsp; by 202.106.187.147 with SMTP; 2 Jul 2002 13:59:27 -0000<br>Received: (qmail 70025 invoked by uid 0); 2 Jul 2002 13:55:46 -0000<br>Received: from mid2.eachnet.com (HELO HeHe) (eachnet@192.168.100.131)<br>&nbsp; by mailhub.eachnet.com with SMTP; 2 Jul 2002 13:55:46 -0000<br>From: "易趣网"&lt;billing@eachnet.com&gt;<br>Subject: 易趣网使用费账单(2002年06月),本月您无须付费<br>To: bborn@sina.com<br><br>找倒关键字 &nbsp;subject from 再找倒发信服务器ip地址 取出发信人的邮件地址
 
将你贴出来的内容,保存为一个文本文件,<br>然后运行以下的代码就会解决。<br>当然关键字符要完全匹配。<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; s:TStrings;<br>&nbsp; s1,s2,s3,sf,Cr:string;<br>&nbsp; i,n:integer;<br>begin<br>&nbsp; cR:=#13#10;<br>&nbsp; s:=TStringList.Create ;<br>&nbsp; sf:='邮件服务器:';<br>&nbsp; s2:='';<br>&nbsp; s.LoadFromFile ('d:/temp/delphi/dd.txt');<br>&nbsp; for i:=0 to s.count-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; s1:=trim(s.Strings);<br>&nbsp; &nbsp; if copy(s1,1,2)='by' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;n:=pos(' with ',s1);<br>&nbsp; &nbsp; &nbsp; &nbsp;sf:=sf+' '+copy(s1,4,n-4);<br>&nbsp; &nbsp; &nbsp; &nbsp;continue;<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; if copy(s1,1,8)='Subject:' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;s2:=s2+'主题:'+trim(copy(s1,9,length(s1)-8))+Cr;<br>&nbsp; &nbsp; &nbsp; &nbsp;continue;<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; if copy(s1,1,5)='From:' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;s1:=trim(copy(s1,6,length(s1)-5));<br>&nbsp; &nbsp; &nbsp; &nbsp;n:=pos('&lt;',s1)+1;<br>&nbsp; &nbsp; &nbsp; &nbsp;s2:=s2+'发信人地址:'+copy(s1,n,length(s1)-n)+Cr;<br>&nbsp; &nbsp; &nbsp; &nbsp;s1:=copy(s1,2,n-4);<br>&nbsp; &nbsp; &nbsp; &nbsp;s2:=s2+'发信人姓名:'+s1+Cr;<br>&nbsp; &nbsp; &nbsp; &nbsp;continue;<br>&nbsp; &nbsp; end;<br><br>&nbsp; end;<br>&nbsp; s.free;<br>&nbsp; s2:=s2+sf;<br>&nbsp; showmessage(s2);<br><br>end;<br>
 
那你说是不是就用这些命令就可以完成<br>几乎所有的取字操作?<br>
 
首先要找规律,命令不是关键的。<br>在 VB 和 Java及Perl 中有专门的字符串匹配,用起来很简单。<br>但是Delhpi 中没有。<br>可以考虑调用脚本语句。
 
接受答案了.
 
顶部