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.
- usingSystem.IO;
- usingSystem.Text;
- usingSystem;
- usingSystem.Text.RegularExpressions;
- namespacePicker
- {
- publicclassProgram
- {
- publicstaticvoidMain(String[]args)
- {
- StreamReadersr=null;
- Stringpattern="";
- if(args.Length>=2)
- {
- sr=newStreamReader(args[0]);
- pattern=args[1];
- }
- else
- {
- Console.WriteLine("!Notenougharguments.");
- return;
- }
- Strings=sr.ReadToEnd();
- sr.Close();
- MatchCollectionmatches=Regex.Matches(s,pattern);
- foreach(Matchmatchinmatches)
- {
- Console.WriteLine(match.ToString());
- }
- Console.WriteLine(":Searchingfinishedwith"+matches.Count+"matches.");
- }
- }
- }