Using system;
Using system. Text. regularexpressions;
Namespace wrox. procsharp. regularexpressionplayaround
{
Class mainentrypoint
{
Static void main ()
{
Find1 ();
Console. Readline ();
}
Static void find1 ()
{
String text = @ "XML has made a major impact in almost every aspect
Software development. Designed as an open, extensible, self-describing
Language, it has become the standard for data and document delivery on
The web. The panoply of XML-related technologies continues to develop
At breakneck speed, to enable validation, navigation, transformation,
Linking, querying, description, and messaging of data .";
String Pattern = @ "/BN/S * Ion/B ";
Matchcollection matches = RegEx. Matches (text, pattern,
Regexoptions. ignorecase | regexoptions. ignorepatternwhitespace |
Regexoptions. explicitcapture );
Writematches (text, matches );
}
Static void find2 ()
{
String text = @ "XML has made a major impact in almost every aspect
Software development. Designed as an open, extensible, self-describing
Language, it has become the standard for data and document delivery on
The web. The panoply of XML-related technologies continues to develop
At breakneck speed, to enable validation, navigation, transformation,
Linking, querying, description, and messaging of data .";
String Pattern = @ "/BN ";
Matchcollection matches = RegEx. Matches (text, pattern,
Regexoptions. ignorecase );
Writematches (text, matches );
}
Static void writematches (string text, matchcollection matches)
{
Console. writeline ("original text was:/n" + TEXT + "/N ");
Console. writeline ("No. of matches:" + matches. Count );
Foreach (match nextmatch in matches)
{
Int Index = nextmatch. index;
String result = nextmatch. tostring ();
Int charsbefore = (index <5 )? Index: 5;
Int fromend = text. Length-index-result. length;
Int charsafter = (fromend <5 )? Fromend: 5;
Int charstodisplay = charsbefore + charsafter + result. length;
Console. writeline ("index: {0},/tstring: {1},/t {2 }",
Index, result,
Text. substring (index-charsbefore, charstodisplay ));
}
}
}
}
Using system;
Using system. text;
Namespace wrox. procsharp. stringencoder
{
Class mainentrypoint
{
Static void main (string [] ARGs)
{
String greetingtext = "hello from all the guys at wrox press .";
Greetingtext + = "We do hope you enjoy this book as much as we enjoyed writing it .";
For (INT I = (INT) 'Z'; I> = (INT) 'A'; I --)
{
Char old = (char) I;
Char new = (char) (I + 1 );
Greetingtext = greetingtext. Replace (old, new );
}
For (INT I = (INT) 'Z'; I> = (INT) 'A'; I --)
{
Char old = (char) I;
Char new = (char) (I + 1 );
Greetingtext = greetingtext. Replace (old, new );
}
Console. writeline ("Encoded:/N" + greetingtext );
Stringbuilder greetingbuilder =
New stringbuilder ("hello from all the guys at wrox press.", 150 );
Greetingbuilder. append ("We do hope you enjoy this book as much as we enjoyed writing it ");
For (INT I = (INT) 'Z'; I> = (INT) 'A'; I --)
{
Char old = (char) I;
Char new = (char) (I + 1 );
Greetingbuilder = greetingbuilder. Replace (old, new );
}
For (INT I = (INT) 'Z'; I> = (INT) 'A'; I --)
{
Char old = (char) I;
Char new = (char) (I + 1 );
Greetingbuilder = greetingbuilder. Replace (old, new );
}
Console. writeline ("Encoded:/N" + greetingbuilder. tostring ());
}
}
}