using System;
using System.Text .RegularExpressions ;
class program
{
static void Main( string[ ] args)
{
string text = txt( ) ;
string pattern = @"t$" ;
Regex reg = new Regex( pattern) ;
MatchCollection m = reg.Matches ( text) ;
show( reg, m) ;
}
static void show( Regex reg, MatchCollection m)
{
Console.WriteLine ( " # of matches is : {0} " , m.Count ) ;
foreach( Match match in m)
{
Console.WriteLine ( "value : {0}\n " , match.Value ) ;
Console.WriteLine ( MatchedWord( match, txt( ) ) ) ;
}
}
static string MatchedWord( Match match, string text)
{
int index = match.Index ;
string sp = "" ;
string ss = "" ;
for ( int i= index; i< 100 ; i++ )
{
ss+= text[ i] ;
if ( text[ i] .Equals ( " " ) ) break ;
}
for ( int i= index; i< 100 ; i-- )
{
sp+= text[ i] ;
if ( text[ i] .Equals ( " " ) ) break ;
}
return sp+ match.Value + ss;
}
static string txt( )
{
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" ;
return text;
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpjbGFzcyBwcm9ncmFtCnsKc3RhdGljIHZvaWQgTWFpbihzdHJpbmdbXSBhcmdzKQp7CnN0cmluZyB0ZXh0ID0gdHh0KCk7CnN0cmluZyBwYXR0ZXJuID0gQCJ0JCI7ClJlZ2V4IHJlZyA9IG5ldyBSZWdleChwYXR0ZXJuKTsKTWF0Y2hDb2xsZWN0aW9uIG0gPSByZWcuTWF0Y2hlcyh0ZXh0KTsKc2hvdyhyZWcsbSk7Cn0KCnN0YXRpYyB2b2lkIHNob3coUmVnZXggcmVnLCBNYXRjaENvbGxlY3Rpb24gbSkKewpDb25zb2xlLldyaXRlTGluZSgiICAjIG9mIG1hdGNoZXMgaXMgOiB7MH0gIixtLkNv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