My Indian software teacher gave me some C # programs (2)

Source: Internet
Author: User

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 ());

}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.