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. commitizen-规范commit-message

    安装指南 安装commitizen sudo npm install -g commitizen 配置 cd到.git所在目录 commitizen init cz-conventional-chan ...

  2. 在ubuntu14.04 64位虚拟机中安装mysql

    因为在win10 系统上手贱的将mysql卸载掉了之后有个插件一直无法正常删除导致只能将mysql装到ubuntu虚拟机上, 宝宝心里都是累啊,所以记录下来自己的安装过程2333 命令行操作: &qu ...

  3. Record:Handle onClick for our custom LinearLayout for Gallery-like HorizontalScrollView

    Handle onClick for our custom LinearLayout for Gallery-like HorizontalScrollView   The post "Im ...

  4. ABAP工作区,内表,标题行的定义和区别

         工作区域跟变量一样,是用来保存数据的.区别是变量只能从中保存一个数据.而工作区域可以存放多个.把多个数据合在一起就成工作区域了.下面我们来看看工作区域是如何定义的吧.定义有四种方法,如下:1 ...

  5. 隐藏UITableView多余的分割线

    先看看没有隐藏是什么效果以及代码是什么情况,这样更加直观

  6. thinkPHP CRUD操作

    数据访问 以 nation 表为例 方法一  => select() ①造模型对象 $naiton = D('Nation');   //也可以使用M()方法 ②查询所有 $a = $natio ...

  7. Java的Package和Classpath

    Package 在Java中,Package是用来包含一系相关实例的集合.这些相关联的实例包括:类.接口.异常.错误以及枚举. Package主要有一些的几点作用: Package可以处理名字冲突,在 ...

  8. linux 服务的操作

    启动和停止服务service 命令用于启动及停止某个服务,例如:service camsd stop    停止 camsd 服务service oracled start   启动 oracled ...

  9. 图片轮播(bootstrap)与 圆角搜索框(纯css)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  10. poj1298 The Hardest Problem Ever 简单题

    链接:http://poj.org/problem?id=1298&lang=default&change=true 简单的入门题目也有这么强悍的技巧啊!! 书上面的代码: 很厉害有没 ...