C Delete Chinese from String (Instance Sharing)

  • 2021-11-24 02:41:00
  • OfStack

Not much to say, please look at the code


/// <summary>
///  Delete Chinese from a string 
/// </summary>
public static string Delete Chinese (string str)
{
  string retValue = str;
  if (System.Text.RegularExpressions.Regex.IsMatch(str, @"[\u4e00-\u9fa5]"))
  {
    retValue = string.Empty;
    var strsStrings = str.ToCharArray();
    for (int index = 0; index < strsStrings.Length; index++)
    {
      if (strsStrings[index] >= 0x4e00 && strsStrings[index] <= 0x9fa5)
      {
        continue;
      }
      retValue += strsStrings[index];
    }
  }
  return retValue;
}

Related articles: