提取字符串中的漢字


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值判斷了

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章