Hur*_*rem 2 c# text streamreader
我正在使用txt或htm文件.目前我正在通过char查找文档char,使用for循环,但我需要逐字查找文本,然后在char中查找单词char.我怎样才能做到这一点?
for (int i = 0; i < text.Length; i++)
{}
Run Code Online (Sandbox Code Playgroud)
一个简单的方法是使用string.Split不带参数(用空格字符分割):
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
{
string line = sr.ReadLine();
string[] words = line.Split();
foreach(string word in words)
{
foreach(Char c in word)
{
// ...
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我以前StreamReader.ReadLine读过整行.
要解析HTML,我会使用像HtmlAgilityPack这样的强大库.
| 归档时间: |
|
| 查看次数: |
12760 次 |
| 最近记录: |