zoukankan      html  css  js  c++  java
  • 正则过滤汉字

    Regex reg = new Regex(@"[\u4e00-\u9fa5]+"); string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n"; string result = reg.Replace(content, ""); richTextBox2.Text = result;

    unsafe static void kickoffChinese3()
            {
                //string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
                char[] chars = content.ToCharArray();
                char[] result = new char[chars.Length];

                fixed (char* pChars = chars)
                {
                    fixed (char* pResult = result)
                    {
                        char* pCurrentChars = pChars;
                        char* pCurrentResult = pResult;
                        char* pLimit = pChars + chars.Length;
                        while (pCurrentChars < pLimit)
                        {
                            if (*pCurrentChars < 0x4E00 || *pCurrentChars > 0x9FA5)
                                *pCurrentResult++ = *pCurrentChars;
                            pCurrentChars++;
                        }
                        *pCurrentResult = '\0';
                    }
                }
                //Console.WriteLine(new string(result));
            }

  • 相关阅读:
    模块jieba库的使用
    模块wordcloud库的使用
    爬取哔哩哔哩网站弹幕
    爬虫讲解
    基本统计值计算
    数据类型及元素元组
    pyinstall的安装及使用
    面向对象介绍
    re模块
    logging模块
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175781.html
Copyright © 2011-2022 走看看