判断一个字符串是否由重复字符串拼接,并返回重复的字符串,

        /// <summary>
        /// 判断一个字符串是否由重复字符串拼接,并返回重复的字符串,
        /// </summary>
        /// <param name="i_Str"></param>
        /// <param name="minLength">默认重复字符串最小长度为3位</param>
        /// <returns></returns>
        private string RtnStr(string i_Str,int minLength=3)
        {
            string Rtn = i_Str; 
            bool IsRe = true;
            try
            {
                string Rtn_1 = string.Empty;


                Rtn_1 = i_Str.Substring(0, minLength);
                    string[] arr = Regex.Split(i_Str, Rtn_1, RegexOptions.IgnoreCase);

                    string ReStr = string.Empty;
                    IsRe = true;
                    foreach (var item in arr)
                    {
                        if (string.IsNullOrEmpty(item)) continue;
                        if (string.IsNullOrEmpty(ReStr)) ReStr = item;
                        if (!item.Equals(ReStr))
                        {
                            IsRe = false;
                            break;
                        } 
                    }
                    if (IsRe)
                    {
                        Rtn = Rtn_1 + ReStr; 
                    } 
            }
            catch (Exception)
            {
                
                throw;
            }

            return Rtn;
        }

  

原文地址:https://www.cnblogs.com/lhlong/p/13640183.html