关于统计单词的问题的继续(10分)

  • 主题发起人 主题发起人 watt
  • 开始时间 开始时间
W

watt

Unregistered / Unconfirmed
GUEST, unregistred user!
前几天我在http://www.delphibbs.com/delphibbs/dispq.asp?lid=3598535上向大虾们请教了统计单词的方法,根据大虾给的提示,我把功能扩展了一下:增加了统计不同单词的功能。可是运行之后达不到预期的效果,麻烦大虾们再给一点建议,下面是我的部分代码:<br>procedure TForm1.Button1Click(Sender: TObject);<br>label outer;<br>//使用goto语句必须在此用label声明,且一旦声明就必须使用<br>begin<br> &nbsp;oString := TStringStream.Create(Memo1.Lines.text);<br> &nbsp;with TParser.Create(oString) do<br> &nbsp;try<br> &nbsp; &nbsp;while(Token &lt;&gt; toEOF) do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if Token = toSymbol<br> &nbsp; &nbsp; &nbsp;then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;//问题可能出在toSymbol<br> &nbsp; &nbsp; &nbsp; &nbsp;for j:=0 to 1000 do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if a[j]=toSymbol then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto outer;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;a:=toSymbol; &nbsp; //我想用一个数组来接收Memo中的所有单词<br> &nbsp; &nbsp; &nbsp; &nbsp;Inc(wordcount);<br> &nbsp; &nbsp; &nbsp; &nbsp;Inc(i);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;outer:<br> &nbsp; &nbsp; &nbsp;NextToken;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;Free;<br> &nbsp; &nbsp;oString.Free;<br> &nbsp;end;<br> &nbsp;Label1.caption:=('单词共:'+inttostr(wordcount)+'个');<br> &nbsp;Label2.caption:=('不同的单词共:'+inttostr(i)+'个');<br> &nbsp;wordcount:=0; //清0<br> &nbsp;i:=0;<br>end;<br>若能解决此问题,菜鸟我将不胜感激,谢谢
 
稍微改一下就好了<br>========================================<br> &nbsp; &nbsp; &nbsp;if Token = toSymbol<br> &nbsp; &nbsp; &nbsp;then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;//问题可能出在toSymbol<br> &nbsp; &nbsp; &nbsp; &nbsp;for j:=0 to 1000 do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if a[j]=toSymbol then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto outer;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;a:=toSymbol; &nbsp; //我想用一个数组来接收Memo中的所有单词<br> &nbsp; &nbsp; &nbsp; &nbsp;Inc(i);<br> &nbsp; &nbsp; &nbsp;outer:<br> &nbsp; &nbsp; &nbsp; &nbsp;Inc(wordcount);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;NextToken;<br>========================================
 
To:韦剑<br> &nbsp; 韦剑大虾,我用你给出的修改方案重新运行了一下,不过还是不行,始终无法统计出不重复的单词的个数。其他高手也帮帮忙想想吧,谢谢了
 
你那个toSymbol应该是始终都被编译器看成了一个东西吧
 
帮忙顶一下,我也想知道怎么统计不同的单词,可是我也不会,呵呵,会的高手们帮忙解决一下呀
 
大虾们帮忙给看看吧,就算是给一点点的提示也好呀,我实在是想不出到底哪儿出错了。
 
把完整代码贴出来吧。
 
我已经把问题给解决了,不过还是感谢韦大虾
 
后退
顶部