各位大哥大姐帮帮忙!一个文本处理问题 ( 积分: 50 )

  • 主题发起人 主题发起人 kytcw
  • 开始时间 开始时间
K

kytcw

Unregistered / Unconfirmed
GUEST, unregistred user!
Memo控件里有如下内容:<br>123456,23456,3456,456,56,6,77,88,99<br>要怎么样才能把他们分开显示在ListView里面?并且只显示其中的3数字个,显示下3个数字必须要按一下按钮.再按一下显示下3个数字.小弟弟我刚刚初学,请各位大哥哥,大姐姐~帮帮我.!!!最后只剩下50分,都给大家了!
 
Memo控件里有如下内容:<br>123456,23456,3456,456,56,6,77,88,99<br>要怎么样才能把他们分开显示在ListView里面?并且只显示其中的3数字个,显示下3个数字必须要按一下按钮.再按一下显示下3个数字.小弟弟我刚刚初学,请各位大哥哥,大姐姐~帮帮我.!!!最后只剩下50分,都给大家了!
 
用substring取memo.lines.string里的數字﹐同時設一個全局變量定位們置﹐按','一個一個取﹐用pos來定位。
 
太巧了,我写考场编排算法的时候用到了这种处理,马上贴代码
 
能不能给个例子呀?我真的不会写,特别想知道怎么按一次按钮每次显示3个数字,谢谢大家了!帮帮忙!谢谢
 
我的代码需要给你整理一下,跟当前无关的给你去掉,并且给你测试好,你不要这么急<br><br>var<br> &nbsp;tpStr, msg: string;<br> &nbsp;Count, Count2,i,tpInt: integer;<br>begin<br> tpStr:='123456,23456,3456,456,56,6,77,88,99';<br> Count:=0;<br> while pos(',',tpStr) &gt; 0 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; inc(Count);<br> &nbsp; &nbsp; tpStr:=copy(tpStr,pos(',',tpStr)+1,length(tpStr)-pos(',',tpStr));<br> &nbsp; &nbsp; end;<br> &nbsp;if length(tpStr) &gt; 0 then<br> &nbsp; &nbsp; inc(Count);<br> &nbsp;ShowMessage(Format('共有%d个分字符串!',[Count]));<br><br> &nbsp;tpStr:='123456,23456,3456,456,56,6,77,88,99';<br> &nbsp;Count2:=0;<br> &nbsp;for i:=0 to Count-1 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; if pos(',',tpStr) &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;tpInt:=strToInt(copy(tpstr,1,pos(',',tpStr)-1));<br> &nbsp; &nbsp; &nbsp; &nbsp;tpStr:=copy(tpStr,Pos(',',tpStr)+1,length(tpStr)-pos(',',tpStr));<br> &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp;tpInt:=strToInt(tpStr);<br> &nbsp; &nbsp; Inc(Count2);<br> &nbsp; &nbsp; msg:=msg+InttoStr(tpInt);<br> &nbsp; &nbsp; if Count2 &lt;&gt; 3 then<br> &nbsp; &nbsp; &nbsp; &nbsp;msg:=msg+'---';<br> &nbsp; &nbsp; if ((i+1) mod 3 = 0) then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage(msg);<br> &nbsp; &nbsp; &nbsp; &nbsp;Count2:=0;<br> &nbsp; &nbsp; &nbsp; &nbsp;msg:='';<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; end;<br>end;
 
如果你不需要得到分字符串对应的整数,可以不用转成整数,如果要针对整数,这个框架一可以了
 
又看了一眼楼主的问题,忽然发现我的理解不太到位,不过楼主可以自己整理出来的
 
怎么第二段代码有错误呢?提示窗口不停的提示.想不出办法来解决,请xfz8129 再帮帮我.看了下代码有点似懂非懂的感觉,刚学Delphi.还有很多要请大家帮帮我.<br>还有就是要怎么样才能把这些数据添加进Listview里面去呢?<br>出错的代码如下:<br>tpStr:='123456,23456,3456,456,56,6,77,88,99';<br> &nbsp;Count2:=0;<br> &nbsp;for i:=0 to Count-1 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; if pos(',',tpStr) &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;tpInt:=strToInt(copy(tpstr,1,pos(',',tpStr)-1));<br> &nbsp; &nbsp; &nbsp; &nbsp;tpStr:=copy(tpStr,Pos(',',tpStr)+1,length(tpStr)-pos(',',tpStr));<br> &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp;tpInt:=strToInt(tpStr);<br> &nbsp; &nbsp; Inc(Count2);<br> &nbsp; &nbsp; msg:=msg+InttoStr(tpInt);<br> &nbsp; &nbsp; if Count2 &lt;&gt; 3 then<br> &nbsp; &nbsp; &nbsp; &nbsp;msg:=msg+'---';<br> &nbsp; &nbsp; if ((i+1) mod 3 = 0) then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage(msg);<br> &nbsp; &nbsp; &nbsp; &nbsp;Count2:=0;<br> &nbsp; &nbsp; &nbsp; &nbsp;msg:='';<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; end;<br>end;
 
把你做好的程序和界面用winrar压缩一下,发给我,给你做个完整的程序算了<br>14574256@163.com
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;lbl1: TLabel;<br> &nbsp; &nbsp;edtStr: TEdit;<br> &nbsp; &nbsp;btnAdd: TButton;<br> &nbsp; &nbsp;lstShow: TListBox;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure btnAddClick(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>var<br> &nbsp;restStr: string;<br><br>procedure TForm1.btnAddClick(Sender: TObject);<br>var<br> &nbsp;count,ipos :Integer;<br> &nbsp;minStr: string;<br>begin<br> &nbsp;count:=0;<br> &nbsp;ipos:=Pos(',',restStr);<br> &nbsp;while ipos &gt; 0 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; minStr:=Copy(restStr,1,ipos-1);//取出第一个小字符串<br> &nbsp; &nbsp; restStr:=Copy(restStr,ipos+1,Length(restStr));//把前面第一个小字符串连同其后逗号截去<br> &nbsp; &nbsp; lstShow.Items.Add(minStr);<br> &nbsp; &nbsp; Inc(count);<br> &nbsp; &nbsp; if count = 3 then<br> &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp; ipos:=pos(',',restStr);<br> &nbsp; &nbsp; end;<br> &nbsp;if restStr &lt;&gt; '' then<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; lstShow.Items.Add(restStr);<br> &nbsp; &nbsp; restStr:='';<br> &nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;restStr:=edtStr.Text;<br>end;<br><br>end.
 
非常感激 xfz8124 的帮助!谢谢
 

Similar threads

回复
0
查看
1K
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部