📄 sample58.cs
字号:
namespace apiBook
{
using System;
using System.Threading;
using System.Globalization;
public class TestCompareInfoClass
{
public static void Main()
{
TestCompareInfoClass t=new TestCompareInfoClass();
string s1="中国人";
string s2="中国";
string s3="中国人爱中国";
CompareInfo test=CompareInfo.GetCompareInfo("zh-CHS");
//使用GetCompareInfo方法初始化CompareInfo类的实例
Console.Write("比较’中国人‘和‘中国’前两个字是否有区别?");
int i=test.Compare(s1,0,2,s2,0,2);
//使用Compare方法比较两字符串
t.DoPrint(i);
Console.Write("比较’中国人‘和‘中国’是否相同?");
i=test.Compare(s1,s2);
t.DoPrint(i);
Console.WriteLine();
Console.Write("字符串s1=\"中国人\"的SortKey=");
Console.WriteLine(test.GetSortKey(s1));
int index=test.IndexOf(s3,s2);
//使用IndexOf方法查看匹配情况
Console.WriteLine();
Console.WriteLine("现在比较s2=\"中国\"在s3=\"中国人爱中国\"的匹配情况");
Console.WriteLine("s2和s3的从第"+index+"下标匹配。");
index=test.LastIndexOf(s3,s2);
//使用LastIndexOf方法查看匹配情况
Console.WriteLine("s2和s3的倒数第"+index+"下标匹配。");
Console.Write("查看s3是否以s1开始?");
Console.WriteLine(test.IsPrefix(s3,s1));
//使用IsPrefix方法查看是否以S1开头
Console.Write("查看s3是否以s1结束?");
Console.WriteLine(test.IsSuffix(s3,s1));
//使用IsSuffix方法查看是否以S1结尾
Console.ReadLine();
}
public void DoPrint(int i)
{
if(i==0)
Console.WriteLine("相同");
else
Console.WriteLine("不相同");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -