关键代码:

        /// <summary>
        /// 判断字符串中是否包含中文
        /// </summary>
        /// <param name="str">需要判断的字符串</param>
        /// <returns>判断结果</returns>
        public static bool HasChinese(this string str)
        {
            return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
        }

单元测试:

        [TestMethod()]
        public void HasChineseTest()
        {
            string _chineseStr1 = "你好Word";
            bool _expected1 = true;
            bool _actual1 = StringToolV2.HasChinese(_chineseStr1);
            Assert.AreEqual(_expected1, _actual1);

            string _chineseStr2 = "Hello World";
            bool _expected2 = false;
            bool _actual2 = StringToolV2.HasChinese(_chineseStr2);
            Assert.AreEqual(_expected2, _actual2);
        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }测试结果:

[C#]判断字符串中是否包含中文的更多相关文章

  1. java判断字符串中是否包含中文 过滤中文

    package com.test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test ...

  2. java 判断字符串中是否包含中文并过滤掉中文

      java判断字符串中是否包含中文并过滤掉中文 CreateTime--2017年9月6日08:48:59 Author:Marydon 1.判断字符串中是否包含中文方法封装 /** * 判断字符串 ...

  3. oracle 如何判断字符串中是否包含中文?超级简单!

      1.情景展示 如何快速的判断出指定字符串中是否包含中文呢? 2.解决方案 通过length()和lengthb()函数的比对结果进行判断. lengthb(string)计算string所占的字节 ...

  4. Java 正则判断一个字符串中是否包含中文

    使用正则判断一个字符串中是否包含中文或者中文字符 代码实现如下: import java.util.regex.Matcher; import java.util.regex.Pattern; /** ...

  5. PHP判断字符串中是否包含指定字符串,支持中文哦

    RT,随手写的 /** * 判断字符串中是否包含指定字符串 * @var source 源字符串 * @var target 要判断的是否包含的字符串 * @return bool */ functi ...

  6. java判断字符串中是否含有中文

    /** * 判断字符串中是否含有中文 */ public static boolean isCNChar(String s){ boolean booleanValue = false; for(in ...

  7. php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpos

    php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpossubstr_count($haystack, $needle [,$o ...

  8. PHP判断字符串中是否含有中文

    <?php $str = "测试中文"; echo $str; echo "<hr>"; //if (preg_match("/^[ ...

  9. Python如何判断字符串中是否有中文

    解决:Python如何判断字符串中是否有中文 In [240]: s Out[240]: '你好aa' In [241]: for i in s: ...: if u'\u4e00' <= i ...

随机推荐

  1. hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值

    Conturbatio Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...

  2. MmSystem播放Wav格式声音

    //MmSystem播放Wav格式声音 //MmSystem 支持 *.wav声音格式 snd ->SoundRecorderuses MmSystem; //引用MmSystem//播放系统声 ...

  3. sphinx 增量索引 及时更新、sphinx indexer索引合成时去旧和过滤办法(转)

    一.sphinx增量索引的设置    数据库中的已有数据很大,又不断有新数据加入到数据库中,也希望能够检索到.全部重新建立索引很消耗资源,因为我们需要更新的数据相比较而言很少.例如.原来的数据有几百万 ...

  4. 去掉html标签和空格等

    <?php$str = '<span style="color:#f00;">good; world</span>';echo $str.'<b ...

  5. python的内存管理机制 图解+Django Web开发学习笔记

    http://www.cnblogs.com/CBDoctor/p/3781078.html http://www.cnblogs.com/vamei/p/3232088.html http://bl ...

  6. 面试题总结之Linux/Shell

    Linux Linux cshrc文件作用 Linux如何起进程/查看进程/杀进程 Linux 文件755 代表什么权限 Linux辅助线程 Linux进程间通信方法 pipeline,msgq... ...

  7. MySQL(16):Select-union(联合查询)

    1. Select-union(联合查询) union用于把来自许多SELECT语句的结果组合到一个结果集合中. 用法: SELECT ...UNION [ALL | DISTINCT]SELECT ...

  8. Android(java)学习笔记118:类继承的注意事项

    /* 继承的注意事项: A:子类只能继承父类所有非私有的成员(成员方法和成员变量) B:子类不能继承父类的构造方法,但是可以通过super(马上讲)关键字去访问父类构造方法. C:不要为了部分功能而去 ...

  9. MySQL(8):数值类型详细分析

    1.日期和时间类型 2.varchar和char 固定长度 (char) 或可变长度 (varchar) 字符数据类型.  例如: a char(10)b varchar(10)都存入'abc'a要求 ...

  10. cxf

    一,cxf webService入门案例 1,jar包 注意版本 使用jdk6和apache-cxf-3.1.2,但cxf-3.1.2已经不支持jdk6,需要jdk7以上 版本用错会报java.lan ...