[C#]判断字符串中是否包含中文
关键代码:
/// <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#]判断字符串中是否包含中文的更多相关文章
- java判断字符串中是否包含中文 过滤中文
package com.test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test ...
- java 判断字符串中是否包含中文并过滤掉中文
java判断字符串中是否包含中文并过滤掉中文 CreateTime--2017年9月6日08:48:59 Author:Marydon 1.判断字符串中是否包含中文方法封装 /** * 判断字符串 ...
- oracle 如何判断字符串中是否包含中文?超级简单!
1.情景展示 如何快速的判断出指定字符串中是否包含中文呢? 2.解决方案 通过length()和lengthb()函数的比对结果进行判断. lengthb(string)计算string所占的字节 ...
- Java 正则判断一个字符串中是否包含中文
使用正则判断一个字符串中是否包含中文或者中文字符 代码实现如下: import java.util.regex.Matcher; import java.util.regex.Pattern; /** ...
- PHP判断字符串中是否包含指定字符串,支持中文哦
RT,随手写的 /** * 判断字符串中是否包含指定字符串 * @var source 源字符串 * @var target 要判断的是否包含的字符串 * @return bool */ functi ...
- java判断字符串中是否含有中文
/** * 判断字符串中是否含有中文 */ public static boolean isCNChar(String s){ boolean booleanValue = false; for(in ...
- php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpos
php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpossubstr_count($haystack, $needle [,$o ...
- PHP判断字符串中是否含有中文
<?php $str = "测试中文"; echo $str; echo "<hr>"; //if (preg_match("/^[ ...
- Python如何判断字符串中是否有中文
解决:Python如何判断字符串中是否有中文 In [240]: s Out[240]: '你好aa' In [241]: for i in s: ...: if u'\u4e00' <= i ...
随机推荐
- 46 关于Linux的I/O重定向
I/O重定向是一个过程,这个过程捕捉一个文件.或命令.或程序.或脚本.甚至代码块(code block)的输出,然后把捕捉到的输出,作为输入发送给另外一个文件.或命令.或程序.或脚本. 1.I/O重定 ...
- Gearman + Nodejs + MySQL UDF异步实现 MySQL 到 Redis 的数据同步
[TOC] 1, 环境 CentOS, MySQL, Redis, Nodejs 2, Redis简介 Redis是一个开源的K-V内存数据库,它的key可以是string/set/hash/list ...
- 查看Linux主机CPU及内存信息
查看CPU信息(型号) # cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c 8 Intel(R) Xeon(R) CPU ...
- [Bootstap] 9. Dropdown
Dropdown Arrow Class In order to create a down arrow like this: , what class should we apply to the ...
- eclipse启动不了报错java was started but returned exit code=13
http://zhidao.baidu.com/question/1367307106041927459.html http://zhidao.baidu.com/question/570567914 ...
- [Effective C++ --022]将成员变量声明为private
这一章并没有什么太多的内容,作者无非想告诉我们一件事:成员变量应该是private. 为此,他列举了以下的理由: 1.成员函数来返回成员变量是非常高效: 2.protected成员变量并不比publi ...
- iOS的崩溃和编译错误
1. Command /bin/sh failed with exit code 127 这是因为mogenerator找不到路径,stackoverflow给出的答案是: If /usr/local ...
- Oracle批量加注释,并生成html
excel连接列名生成oracle注释 notes: A2为列名,B2为注释 ="comment on column ColAgreementHeader."&A2& ...
- mysql:通用查询日志general_log
1.通用查询日志:记录建立的客户端连接和执行的语句,通用查询日志默认情况下不是开启的,通用查询日志是以文本方式存放的 当需要采样分析的时候手工开启: SET Global general_log=1; ...
- logstash input jdbc连接数据库
示例 以下配置能够实现从 SQL Server 数据库中查询数据,并增量式的把数据库记录导入到 ES 中. 1. 查询的 SQL 语句在 statement_filepath => " ...