• 我的印度软件老师,给的 几个C# PROGRAMS (2)


    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 of
                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 of
                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/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());
         
          }
       }
    }

  • 相关阅读:
    Threejs学习 一
    Mapbox的表达式
    mapbox 不加载地图
    SQL Server将查询出数据进行列转行操作
    SQL Server 常用近百条SQL语句(收藏版)
    SQL Server DATEDIFF() 函数用法
    SQL Server 数据库开启日志CDC记录,导致SQL Server 数据库日志异常增大
    查询SQL Server数据库使用的版本号信息
    windows 无法启动 SQL Server (MSSQLSERVER) 服务(位于本地计算机上)。错误 1069由于登入失败而无法启动 。
    SQL Server 不同数据间建立链接服务器进行连接查询
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9410251.html
Copyright © 2020-2023  润新知