BDN参考的写法:http://bdn.borland.com/article/26380
procedure TForm1.Button6Click(Sender: TObject);
var
theParser: TParser;
oString: TStringStream;
str:AnsiString;
Pos,Line:integer;
begin
oString := TStringStream.Create(Memo1.Lines.text);
oString.Position := 0;
theParser:= TParser.Create(oString);
while (theParser.Token <> toEOF) do //while we're in the file
begin
//Get Token
str:=theParser.TokenString();
//Get the position in the stream
Pos:=theParser.SourcePos();
//Get the line number
Line:=theParser.SourceLine;
//Get token type
case (theParser.Token) of
toSymbol:
Memo2.Lines.Add(
procedure TForm1.Button6Click(Sender: TObject);
var
theParser: TParser;
oString: TStringStream;
str:AnsiString;
Pos,Line:integer;
begin
oString := TStringStream.Create(Memo1.Lines.text);
oString.Position := 0;
theParser:= TParser.Create(oString);
while (theParser.Token <> toEOF) do //while we're in the file
begin
//Get Token
str:=theParser.TokenString();
//Get the position in the stream
Pos:=theParser.SourcePos();
//Get the line number
Line:=theParser.SourceLine;
//Get token type
case (theParser.Token) of
toSymbol:
Memo2.Lines.Add(

这篇博客介绍了如何在Delphi中使用TParser类来解析字符串,展示了两种不同的用法,一种用于常规解析,另一种用于词频统计。文章通过示例代码详细解释了TParser在处理不同类型的词(如符号、整数、浮点数和字符串)以及如何处理不成对的单引号导致的异常。
最低0.47元/天 解锁文章
4918

被折叠的 条评论
为什么被折叠?



