private void button1_Click(object sender, System.EventArgs e)
{
if(txtIN.Text != "")
{
int i = 0;
string strIN = txtIN.Text;
string temp;
byte[] array = new byte[2];
txtOUT.Text = "";
for(i = 0;i < strIN.Length;i++)
{
temp = strIN.Substring(i,1);
array = Encoding.Default.GetBytes(temp);
if(array.Length != 1)
{
txtOUT.Text = txtOUT.Text + temp;
}
}
}
}
按钮点击的时候将txtIN中字符串中的汉字显示到txtOUT中。
foreach(char c in str)
{
if(char.GetUnicodeCategory(c) == UnicodeCategory.OtherLetter){
Console.Write(c.ToString());
}
}
中文是OtherLetter,如果string里还有其它语言字符,只能获取u值判断了
博客给出代码实现按钮点击时,将txtIN中字符串里的汉字显示到txtOUT中。通过遍历字符串,利用编码判断字节长度提取汉字。还提到若字符串含其他语言字符,可通过获取u值判断,中文属于OtherLetter类别。
4794

被折叠的 条评论
为什么被折叠?



