Just nu i M3-nätverket
Jump to content

C# - ta ut ett ord i en text


A-K

Recommended Posts

Ett exempel:

using System;

using System.IO;

using System.Text.RegularExpressions;

 

namespace Grep

{

class Class1

{

[sTAThread]

static void Main(string[] args)

{

String file = @"c:\temp\howdy.txt";

String pattern = "Howdy";

 

Regex reg = new Regex(pattern);

 

StreamReader reader = new StreamReader(file);

 

while (reader.Peek() != -1)

{

String line = reader.ReadLine();

Match m = reg.Match(line);

if (m.Success) Console.WriteLine(m.ToString());

}

reader.Close();

}

}

}

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...