123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace SCC.Common
- {
-
-
-
- public static partial class StringHelper
- {
- #region ContainsChinese(是否包含中文)
-
-
-
-
- public static bool ContainsChinese(string text)
- {
- const string pattern = "[\u4e00-\u9fa5]+";
- return Regex.IsMatch(text, pattern);
- }
- #endregion
- #region ContainsNumber(是否包含数字)
-
-
-
-
- public static bool ContainsNumber(string text)
- {
- const string pattern = "[0-9]+";
- return Regex.IsMatch(text, pattern);
- }
- #endregion
- #region Distinct(去除重复)
-
-
-
-
- public static string Distinct(string value)
- {
- var array = value.ToCharArray();
- return new string(array.Distinct().ToArray());
- }
- #endregion
-
- #region 删除最后一个字符之后的字符
-
-
-
- public static string DelLastComma(string str)
- {
- return str.Substring(0, str.LastIndexOf(",", StringComparison.Ordinal));
- }
-
-
-
- public static string DelLastChar(string str, string strchar)
- {
- return str.Substring(0, str.LastIndexOf(strchar, StringComparison.Ordinal));
- }
-
-
-
-
-
-
- public static string DelLastLength(string str, int Length)
- {
- if (string.IsNullOrEmpty(str))
- return "";
- str = str.Substring(0, str.Length - Length);
- return str;
- }
- #endregion
- #region 快速验证一个字符串是否符合指定的正则表达式
-
-
-
-
-
-
- public static bool QuickValidate(string express, string value)
- {
- if (value == null) return false;
- Regex myRegex = new Regex(express);
- if (value.Length == 0)
- {
- return false;
- }
- return myRegex.IsMatch(value);
- }
- #endregion
- }
- }
|