List<string[]> list = File.ReadLines("YourFile.txt")
.Select(r => r.TrimEnd('#'))
.Select(line => line.Split(','))
.ToList();

or

List<string[]> list = File.ReadLines("YourFile.txt")
.Select(r => r.TrimEnd('#').Split(','))
.ToList();

File.ReadLines would read the file line by line.

.Select(r => r.TrimEnd('#')) would remove the # from end of the line
.Select(line => line.Split(',')) would split the line on comma and return an array of string items.
ToList() would give you a List<string[]> back.

using System;

public class Example
{
public static void Main()
{
string[] separators = {",", ".", "!", "?", ";", ":", " "};
string value = "The handsome, energetic, young dog was playing with his smaller, more lethargic litter mate.";
string[] words = value.Split(separators, StringSplitOptions.RemoveEmptyEntries);
foreach (var word in words)
Console.WriteLine(word);
}
}
StreamReader sr = new StreamReader(@monsterLocation);
int searchId = monsterId;
int actualId = ;
string name = "(Not found)";
string[] details = null;
string line = null;
while ((line = sr.ReadLine()) != null)
{
line = line.Trim();
if (line == "") continue;
details = line.Split('\t');
actualId = int.Parse(details[]);
if (actualId == searchId)
{
name = details[].Replace("\"", "");
break;
}
}
sr.Close();
Messagebox.shou("Result:" +name);
 

逐行读取txt文件,使用Linq与StreamReader的Readline方法的更多相关文章

  1. 别再用"while (!feof(file))"来逐行读取txt文件了!

    起因 执行一个C/C++程序出现segment fault.它逐行读取文本文件,每一行是一个图片名字,然后读图.处理图像,etc. 发现最后一次读取的文件名不存在(空的). 正确的逐行读取txt文件 ...

  2. python 逐行读取txt文件

    逐行读取txt文件 path = r'D:\123456\1.txt'with open(path, 'r', encoding='utf-8') as f:    for line in f:   ...

  3. 3.C++逐行读取txt文件数据,利用getline -windows编程

      引言:今天学会了getline的用法,顺手编写一个逐行读取txt文件的程序.关于getline的用法可以看我之前的博客:2.C++标准库函数:getline函数 定界流输入截取函数 -zobol的 ...

  4. php逐行读取txt文件写入数组的方法

    使用说明: 采用fopen 方法,逐行读取数据,并使用feof($fp)  判断是否文件截止,最后通过filter() 方法,去除空白行,得到所需数据 $file = fopen("user ...

  5. php逐行读取.txt文件内容,并解析每行内容

    // 读取nlp text 并存到mongodb public function readNLP(&$errorCode,&$errorMessage) { try{ // $_SER ...

  6. 逐行读取txt文件并存入到数组中

    get_file_contents_on_line.php $file = fopen("log.txt", "r"); $user=array(); $i=0 ...

  7. JAVA逐行读取TXT文件

    package help; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; imp ...

  8. 逐行读取txt文件,分割,写入txt。。。上传,下载

    s = [] f  = open('querylist.txt','r') #由于我使用的pycharm已经设置完了路径,因此我直接写了文件名 for lines in f:     ls = lin ...

  9. 逐行读取txt文件

    header("Content-type:text/html; charset=utf-8"); $handle = fopen('test.php', 'r') or die(' ...

随机推荐

  1. HDU 5512

    http://acm.hdu.edu.cn/showproblem.php?pid=5512 gcd(a,b)的位置都是可以选的,之后判断一下奇偶 #include <iostream> ...

  2. Kruskal(测试源代码)

    1.此程序为c++程序 2.以下代码可实现手动输入,即去掉代码中的/*...*/注释符,并同时去掉赋值代码段 3.源代码 #include<iostream> using namespac ...

  3. Lua查找表元素过程(元表、__index方法是如何工作的)

    近日开始研究Lua,在元表的使用上照猫画虎地搞了两下,实现了“面向对象”,但究其本质却略有不解,后咨询牛哥得解,特此记录. Lua的表本质其实是个类似HashMap的东西,其元素是很多的Key-Val ...

  4. 读取手机上所有应用程序并显示(APP)

    pd = ProgressDialog.show(getActivity(), "请稍候..", "正在收集软件信息...", true,false); Thr ...

  5. Mac、Linux更换命令行svn diff为P4Merge、vimdiff

    2015-01-21 21:25:52 这里先把那个程序员大神的博客地址贴一下(PS:大神,我不是为了抄袭哦,真是怕自己忘记了),http://www.ccvita.com/445.html,里面还有 ...

  6. Xshell访问虚拟机内Linux

    这段时间在家,需要用到Linux,身边的电脑硬盘很小,装双系统用的频率也不高还浪费磁盘空间,还是使用虚拟机,通过Xshell管理虚拟机内Ubuntu还是比较方便的.很早之前学习hadoop的时候就是用 ...

  7. Sublime Text2 快捷键汇总

    一个好的编辑器,能大大提高编程的效率.如果能熟知软件的快捷键,那更能让你得心印手.这些内容都是我网上和自己实际使用过程中所收集而来的,在网络上应该也算比较全面的了吧.欢迎大家补充,我也会在以后慢慢添加 ...

  8. STM32中的PWM的频率和占空比的设置

    转于http://blog.csdn.net/liming0931/article/details/8491468 下面的这个是stm32的定时器逻辑图,上来有助于理解:   TIM3的ARR寄存器和 ...

  9. 一个assert的写法

    ]; int assert_buf_len; #ifdef XXX_DEBUG #define assert(expr, ...) \ do{ \ if ((!(expr))) \ {\ char * ...

  10. Android之QQ登录界面

    首先过程中碰到的几个问题: 1.对 EditText 进行自定义背景 2.运行时自动 EditText 自动获得焦点 3.在获得焦点时即清空 hint ,而不是输入后清空 4.清空按钮的出现时机(在得 ...