第五次作业
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
string s1 = "One Two Three Four";
string sx = (string)s1.Clone(); //s1复制到sx
Console.WriteLine(Object.ReferenceEquals(s1, sx)); //相同返回true sx += " Five";//sx修改
Console.WriteLine(Object.ReferenceEquals(s1, sx)); // 不同返回False
Console.WriteLine(sx); // 显示"One Two Three Four Five"
//Console.ReadLine();
string s2 = "pppp";
int result;
result = string.Compare(s1, s2);//逐个比较其Unicode值
Console.WriteLine(result);
//Console.ReadLine();
s2 = s1.Substring(0, 3);//提取One 赋值给s2
Console.WriteLine(s2);
//Console.ReadLine();
string words = "One,Two,Three Liberty Associates, Inc.";
string[] splitedString = words.Split(' ', ',');//每当有空格和逗号的时候取出来丢进splitedString数组中
foreach (string s in splitedString)
{
Console.WriteLine(s);
}
string s3 = "One,Two,Three Liberty Associates, Inc.";
Regex theRegex = new Regex(" |, |,");
StringBuilder sBuilder = new StringBuilder();
int id = 1;
foreach(string subString in theRegex.Split(s3))
{
sBuilder.AppendFormat("{0}: {1}\n", id++, subString);
}
Console.WriteLine("{0}", sBuilder);//正则表达式
Console.ReadLine();
}
}
}