📄 sample62.cs
字号:
namespace apiBook
{
using System;
using System.Globalization;
public class TestStringInfoClass
{
public static void Main()
{
StringInfo testSI=new StringInfo();
int counter=0;
string s="China";
Console.WriteLine("字符串'China'的第一个文本元素:"+StringInfo.GetNextTextElement(s));
//使用 GetNextTextElement(string str)方法获取字符串中的第一个文本元素
Console.WriteLine("字符串'China'的第三个文本元素:"+StringInfo.GetNextTextElement(s,2));
//使用 GetNextTextElement(string str,int index)方法获取字符串中的第三个文本元素
TextElementEnumerator t=StringInfo.GetTextElementEnumerator(s);
//使用GetTextElementEnumerator方法获取可以循环访问整个字符串的文本元素的枚举数。
int[] iA=StringInfo.ParseCombiningCharacters(s);
//使用ParseCombiningCharacters方法获取字符串中每个基字符、高代理项或控制字符的索引
while(t.MoveNext())
{
counter++;
Console.WriteLine("TextElementEnumerator枚举第"+counter+"值:"+t.Current+";"+"索引为:"+iA[counter-1]);
}
Console.ReadLine();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -