noteswiki

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

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 = 0;
            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[0]);
                if (actualId == searchId)
                {
                    name = details[2].Replace("\"", "");
                    break;
                }
            }
            sr.Close();
            Messagebox.shou("Result:" +name);
 

 

posted on 2016-10-30 15:09  noteswiki  阅读(2852)  评论(0编辑  收藏  举报