fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. class program
  5. {
  6. static void Main(string[] args)
  7. {
  8. string text = txt();
  9. string pattern = @"t$";
  10. Regex reg = new Regex(pattern);
  11. MatchCollection m = reg.Matches(text);
  12. show(reg,m);
  13. }
  14.  
  15. static void show(Regex reg, MatchCollection m)
  16. {
  17. Console.WriteLine(" # of matches is : {0} ",m.Count);
  18. foreach(Match match in m)
  19. {
  20. Console.WriteLine("value : {0}\n", match.Value);
  21.  
  22. Console.WriteLine(MatchedWord(match,txt()));
  23.  
  24.  
  25. }
  26. }
  27. static string MatchedWord(Match match, string text)
  28. {
  29. int index = match.Index;
  30. string sp ="";
  31. string ss ="";
  32. for(int i=index;i<100;i++)
  33. {
  34. ss+=text[i];
  35. if(text[i].Equals(" ")) break;
  36. }
  37. for(int i=index;i<100;i--)
  38. {
  39. sp+=text[i];
  40. if(text[i].Equals(" ")) break;
  41. }
  42.  
  43. return sp+match.Value+ss;
  44. }
  45.  
  46. static string txt()
  47. {
  48.  
  49. string text = "A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects. There's no null-terminating character at the end of a C# string; therefore a C# string can contain any number of embedded null characters ('\0'). The Length property of a string represents the number of Char objects it contains, not the number of Unicode characters. To access the individual Unicode code points in a string, use the StringInfo object";
  50. return text;
  51. }
  52. }
Success #stdin #stdout 0.08s 25268KB
stdin
Standard input is empty
stdout
  # of matches is : 1 
value : t

t