C#: 从英文句子中提取单词
作者: 李嘉 日期: 2009-04-30 19:34
HTML Editor有个spell check功能,需要对整篇英文文章进行单词验证,在后台写一个Js web service for c#,用于从文章中提取单词,提出单词的函数如下:
preivate void getLetter(string ptext) {
char[] separators = { ' ', ',', '?', ':', '!', '"', ';', '(', ')', '.', ''', '_', '—','-' };
int startpos=0;
int endpos=0;
do
{
endpos=mystring.IndexOfAny(separators,startpos);
if ( endpos==-1 ) endpos=ptext.Length;
if ( endpos!=startpos )
Response.Write(ptext.Substring( startpos,(endpos-startpos)) + "<br/>");
startpos=(endpos+1);
}
while(startpos<ptext.Length);
}
在asp.net 2.0环境下测试成功。
订阅
上一篇
返回
下一篇
