关键代码:

        /// <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. NYOJ109 数列转换 【守恒法】

    数列转换 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描写叙述 有一个数列a1,a2,a3...an,每次能够从中随意选三个相邻的数ai-1 ,ai , ai+1 ,进行例 ...

  2. VMWare9下基于Ubuntu12.10搭建Hadoop-1.2.1集群

    VMWare9下基于Ubuntu12.10搭建Hadoop-1.2.1集群 下一篇:VMWare9下基于Ubuntu12.10搭建Hadoop-1.2.1集群-整合Zookeeper和Hbase 近期 ...

  3. 获取设置dom属性

    getAttribute():获取dom节点属性,带一个参数,表示要获取的属性使用方法:object.getAttribute("id"); setAttribute():设置do ...

  4. C#_datatable 写入大量数据_BulkCopy

    using Microsoft.Win32; using System; using System.Collections.Generic; using System.Configuration; u ...

  5. Models and the ServiceManager

    Models and the ServiceManager In the previous chapter we've learned how to create a "Hello Worl ...

  6. iOS 中的 block 是如何持有对象的

    Block 是 Objective-C 中笔者最喜欢的特性,它为 Objective-C 这门语言提供了强大的函数式编程能力,而最近苹果推出的很多新的 API 都已经开始原生的支持 block 语法, ...

  7. chrome,firefox

    chrome开发者工具 firefox插件httpfox

  8. nodejs设置NODE_ENV环境变量

    看下app.js文件中的一部分代码,如下: //开发环境错误处理 // will print stacktrace if (app.get('env') === 'development') { ap ...

  9. JSON对象和string的相互转换

    JSON.stringify(obj) 将JSON转为字符串. JSON.parse(string) 将字符串转为JSON格式.

  10. 安装Numpy和matplotlib

    (1)测试程序     这是我从网上(http://www.open-open.com/lib/view/open1393488232380.html)找到的一个使用Numpy和matplotlib的 ...