第十二节课

79 阅读1分钟

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks;

namespace tiredthless { public class person//所有的类都有一个基类object { public void SayHello() { Console.WriteLine("你好"); } } public class Teacher : person { public void talk() { Console.WriteLine("聊天"); } } internal class Class1 { static void Main(string[] args) { Teacher teacher = new Teacher(); teacher.talk(); teacher.SayHello(); person person1 = (person)teacher;//里氏转换 //检测字符串 识别字符串 替换 可能判断是不是要的字符串 //正则表达式 判断的字符串 ,正则表达式 //string pattern = @"^[1-9][0-9]{4,9}@qq.com$"; string str = Convert.ToString(Console.ReadLine()); //Console.WriteLine(Regex.IsMatch(str,pattern));//返回一个布尔值 //替换 //Console.WriteLine(Regex.Replace(str, "3", "哈哈哈")); Match match = Regex.Match(str,"^3"); Console.WriteLine(match); MatchCollection matchCollection = Regex.Matches(str, "[a-z]"); Console.WriteLine(match); foreach(Match i in matchCollection) { Console.WriteLine(i.ToString()); } } } }