一些有用的UtilityExtend小方法
public static bool StartBy(this string thisValue, params string[] startBy) { foreach (string item in startBy) { if (thisValue.StartsWith(item)) return true; } return false; } public static bool StartBy(this string thisValue, string startBy, char splitSign) { string[] starts = startBy.Split(splitSign); if (starts.Length > 0) foreach (string item in starts) { if (thisValue.StartsWith(item)) return true; } return false; } public static bool IsMatch(this string thisValue, string regexPattern) { return Regex.IsMatch(thisValue, regexPattern); } public static string ReplaceString(this string thisValue, string regexPattern, string replacement) { //Bug Fix if (!string.IsNullOrEmpty(thisValue)) { return Regex.Replace(thisValue, regexPattern, replacement, RegexOptions.IgnoreCase); } return string.Empty; } public static bool IsIn(this string thisValue, params string[] stringCollect) { if (stringCollect == null || stringCollect.Length <= 0) return false; return Array.IndexOf(stringCollect, thisValue) > -1; } public static T IfNullThen<T>(this object thisValue, T val) { return thisValue == null ? val : (T) thisValue; } public static string[] GetSubString(this string thisValue, string regexPattern) { string[] result = null; MatchCollection collection = Regex.Matches(thisValue, regexPattern, RegexOptions.IgnoreCase); if (collection.Count > 0) { result = new string[collection.Count]; for (int i = 0; i < collection.Count; i++) { result[i] = collection[i].Value; } } return result; } public static string GetHashCode(this string thisValue, int leftLength) { string hashCode = Newegg.BigData.Framework.Common.ShareFunctions.GetHashCode(thisValue); return hashCode.Length >= 4 ? hashCode.Substring(0, leftLength) : hashCode; } public static string GetRowKeyHashCode(this string thisValue) { return thisValue.GetHashCode(4); }
如果您觉得本文对你有用,不妨帮忙点个赞,或者在评论里给我一句赞美,小小成就都是今后继续为大家编写优质文章的动力!
欢迎您持续关注我的博客:)
版权所有,欢迎保留原文链接进行转载:)