字符串剪切方法

         /// <summary>
        /// 将指定字符串进行剪切
        /// </summary>
        /// <param name="oldStr">字符串</param>
        /// <param name="marLenth">指定长度</param>
        /// <param name="endWith">尾部</param>
        /// <returns></returns>
        public static  string StringTruncate(string oldStr,int marLenth,string endWith)
        {
            if (string.IsNullOrEmpty(oldStr))
            {
                return endWith;
            }
            if (marLenth < 1)
            {
                throw new Exception("返回的字符串长度必须大于【0】");
            }
            if (oldStr.Length>marLenth)
            {
                string strTmp = oldStr.Substring(0, marLenth);
                if (string.IsNullOrEmpty(endWith))
                {
                    return strTmp;
                }
                else
                {
                    return strTmp + endWith;
                }
            }
            return oldStr;
        }

posted on 2010-04-08 13:12  流云飘鹤  阅读(387)  评论(0编辑  收藏  举报

导航