示例#1
0
        /// <summary>
        /// 判断一个ip是否在另一个ip内
        /// </summary>
        /// <param name="sourceIP">检测ip</param>
        /// <param name="targetIP">匹配ip</param>
        /// <returns></returns>
        public static bool InIP(string sourceIP, string targetIP)
        {
            if (string.IsNullOrEmpty(sourceIP) || string.IsNullOrEmpty(targetIP))
            {
                return(false);
            }

            string[] sourceIPBlockList = StringHelper.SplitString(sourceIP, @".");
            string[] targetIPBlockList = StringHelper.SplitString(targetIP, @".");

            int sourceIPBlockListLength = sourceIPBlockList.Length;

            for (int i = 0; i < sourceIPBlockListLength; i++)
            {
                if (targetIPBlockList[i] == "*")
                {
                    return(true);
                }

                if (sourceIPBlockList[i] != targetIPBlockList[i])
                {
                    return(false);
                }
                else
                {
                    if (i == 3)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// 移除数组中的指定项
        /// </summary>
        /// <param name="array">源数组</param>
        /// <param name="removeItem">要移除的项</param>
        /// <param name="removeBackspace">是否移除空格</param>
        /// <param name="ignoreCase">是否忽略大小写</param>
        /// <returns></returns>
        public static string[] RemoveArrayItem(string[] array, string removeItem, bool removeBackspace, bool ignoreCase)
        {
            if (array != null && array.Length > 0)
            {
                StringBuilder arrayStr = new StringBuilder();
                if (ignoreCase)
                {
                    removeItem = removeItem.ToLower();
                }
                string temp = "";
                foreach (string item in array)
                {
                    if (ignoreCase)
                    {
                        temp = item.ToLower();
                    }
                    else
                    {
                        temp = item;
                    }

                    if (temp != removeItem)
                    {
                        arrayStr.AppendFormat("{0}_", removeBackspace ? item.Trim() : item);
                    }
                }

                return(StringHelper.SplitString(arrayStr.Remove(arrayStr.Length - 1, 1).ToString(), "_"));
            }

            return(array);
        }
示例#3
0
        /// <summary>
        /// 删除字符串中的空行
        /// </summary>
        /// <returns></returns>
        public static string DeleteNullOrSpaceRow(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return("");
            }

            string[]      tempArray = StringHelper.SplitString(s, "\r\n");
            StringBuilder result    = new StringBuilder();

            foreach (string item in tempArray)
            {
                if (!string.IsNullOrWhiteSpace(item))
                {
                    result.AppendFormat("{0}\r\n", item);
                }
            }
            if (result.Length > 0)
            {
                result.Remove(result.Length - 2, 2);
            }
            return(result.ToString());
        }
示例#4
0
 /// <summary>
 /// 去除字符串中的重复元素
 /// </summary>
 /// <returns></returns>
 public static string GetUniqueString(string s, string splitStr)
 {
     return(ObjectArrayToString(RemoveRepeaterItem(StringHelper.SplitString(s, splitStr)), splitStr));
 }
示例#5
0
 /// <summary>
 /// 移除字符串中的指定项
 /// </summary>
 /// <param name="s">源字符串</param>
 /// <returns></returns>
 public static string[] RemoveStringItem(string s)
 {
     return(RemoveArrayItem(StringHelper.SplitString(s), "", true, false));
 }
示例#6
0
 /// <summary>
 /// 判断字符串是否在字符串中
 /// </summary>
 public static bool IsInArray(string s, string array)
 {
     return(IsInArray(s, StringHelper.SplitString(array, ","), false));
 }
示例#7
0
 /// <summary>
 /// 判断字符串是否在字符串中
 /// </summary>
 public static bool IsInArray(string s, string array, string splitStr, bool ignoreCase)
 {
     return(IsInArray(s, StringHelper.SplitString(array, splitStr), ignoreCase));
 }
示例#8
0
 /// <summary>
 /// 是否是数值(包括整数和小数)
 /// </summary>
 public static bool IsNumericRule(string numericRuleStr, string splitChar)
 {
     return(IsNumericArray(StringHelper.SplitString(numericRuleStr, splitChar)));
 }
示例#9
0
 /// <summary>
 /// 判断当前时间是否在指定的时间段内
 /// </summary>
 /// <param name="periodStr">指定时间段</param>
 /// <param name="liePeriod">所处时间段</param>
 /// <returns></returns>
 public static bool BetweenPeriod(string periodStr, out string liePeriod)
 {
     string[] periodList = StringHelper.SplitString(periodStr, "\n");
     return(BetweenPeriod(periodList, out liePeriod));
 }
示例#10
0
 /// <summary>
 /// 判断一个ip是否在另一个ip内
 /// </summary>
 /// <param name="sourceIP">检测ip</param>
 /// <param name="targetIPStr">匹配ip</param>
 /// <returns></returns>
 public static bool InIPList(string sourceIP, string targetIPStr)
 {
     string[] targetIPList = StringHelper.SplitString(targetIPStr, "\n");
     return(InIPList(sourceIP, targetIPList));
 }