• 一些有用的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);
            }
    

      

  • 相关阅读:
    GitHub 更新fork的代码
    robotframework出现错误:Keyword 'AppiumLibrary.Open Application' expected 1 to 2 non-keyword arguments,got 5.
    adb命令积累
    appium测试android环境搭建(win7)
    小明的自留地
    转载:appium踩过的坑
    junit3和junit4的使用区别如下
    Python线程指南
    实现ie低版本支持input type="number"
    LODOP打印开发
  • 原文地址:https://www.cnblogs.com/Wolfmanlq/p/4183404.html
Copyright © 2020-2023  润新知