`
omygege
  • 浏览: 1353497 次
文章分类
社区版块
存档分类
最新评论

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.
  1. usingSystem.IO;
  2. usingSystem.Text;
  3. usingSystem;
  4. usingSystem.Text.RegularExpressions;
  5. namespacePicker
  6. {
  7. publicclassProgram
  8. {
  9. publicstaticvoidMain(String[]args)
  10. {
  11. StreamReadersr=null;
  12. Stringpattern="";
  13. if(args.Length>=2)
  14. {
  15. sr=newStreamReader(args[0]);
  16. pattern=args[1];
  17. }
  18. else
  19. {
  20. Console.WriteLine("!Notenougharguments.");
  21. return;
  22. }
  23. Strings=sr.ReadToEnd();
  24. sr.Close();
  25. MatchCollectionmatches=Regex.Matches(s,pattern);
  26. foreach(Matchmatchinmatches)
  27. {
  28. Console.WriteLine(match.ToString());
  29. }
  30. Console.WriteLine(":Searchingfinishedwith"+matches.Count+"matches.");
  31. }
  32. }
  33. }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics