Element Picker (C#, Regular Expression)
The following code picks element from a text file according to the pattern specified.
It is first used in collecting source file names from a vc project file in order to list them in a common makefile.
It is first used in collecting source file names from a vc project file in order to list them in a common makefile.
- using System.IO;
- using System.Text;
- using System;
- using System.Text.RegularExpressions;
- namespace Picker
- {
- public class Program
- {
- public static void Main(String[] args)
- {
- StreamReader sr = null;
- String pattern = "";
- if (args.Length >= 2)
- {
- sr = new StreamReader(args[0]);
- pattern = args[1];
- }
- else
- {
- Console.WriteLine("! Not enough arguments.");
- return;
- }
- String s = sr.ReadToEnd();
- sr.Close();
- MatchCollection matches = Regex.Matches(s, pattern);
- foreach (Match match in matches)
- {
- Console.WriteLine(match.ToString());
- }
- Console.WriteLine(": Searching finished with " + matches.Count + " matches.");
- }
- }
- }
enjoy every minute of an appless, googless and oracless life