C#通过关键字访问文本特定内容
2014-06-13 22:07
399 查看
//path:如"assets/a.txt" , key:关键字 string Read_File(string path, string key) { StreamReader sr = null; try{ sr = File.OpenText (path); }catch(Exception e) { return "加载失败"; } string text=""; string line; string nextLine; while ((line=sr.ReadLine())!=null) { if(line == key) { while((nextLine=sr.ReadLine ())!=null && nextLine!="//") { text += nextLine+"\n"; } } } sr.Close (); sr.Dispose (); return text; }
a.txt:
...
note
abcd
efg
//
...
string text = ReadFile("a.txt", "note");
则text = "abcd\nefg\n";
相关文章推荐
- C#中实现zip协议,通过WebRequest查询zip文件内容。统一访问接口
- C#通过http访问olap
- C#用HttpWebRequest通过代理服务器验证后抓取网页内容
- C#关键字 之 访问与上下文
- HTMLParser使用详解(3)- 通过Filter访问内容
- C#用HttpWebRequest通过代理服务器验证后抓取网页内容
- 通过text提供的本地地址 显示文本内容
- HTMLParser使用详解(3)- 通过Filter访问内容
- C#用HttpWebRequest通过代理服务器验证后抓取网页内容
- C# 参考之访问关键字:base、this
- HTMLParser使用详解(3)- 通过Filter访问内容
- C# Visual Studio 2005中将一个TextBox中的内容通过FileStream写到文件中
- 用标准ACL拒绝特定主机通过telnet进行访问
- C# 参考之访问关键字:base、this
- HTMLParser使用详解(4)- 通过Visitor访问内容
- 怎么通过sql语句访问另外一个库的内容
- C# 参考之访问关键字:base、this
- C# 参考之访问关键字:base、this
- 在 C#中, 程序间的依赖项通过符号而不是文本来控制
- HTMLParser使用详解(4)- 通过Visitor访问内容