37 lines
852 B
C#
37 lines
852 B
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace HuanMeng.DotNetCore.Utility;
|
||
|
||
/// <summary>
|
||
/// 字符串扩展
|
||
/// </summary>
|
||
public static class StringExtend
|
||
{
|
||
/// <summary>
|
||
/// 判断字符串是否包含中文字符(使用字符遍历)
|
||
/// </summary>
|
||
/// <param name="input">需要检查的字符串</param>
|
||
/// <returns>如果包含中文字符,则返回 true;否则返回 false</returns>
|
||
public static bool ContainsChineseOptimized(this string input)
|
||
{
|
||
if (string.IsNullOrEmpty(input))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
foreach (char c in input)
|
||
{
|
||
if (c >= '\u4e00' && c <= '\u9fa5')
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
}
|