码迷,mamicode.com
首页 > Windows程序 > 详细

C# 取文本中间

时间:2016-08-29 22:44:32      阅读:1610      评论:0      收藏:0      [点我收藏+]

标签:

        /// <summary>  
        /// 取中间文本  
        /// </summary>  
        /// <param name="SumString">总文本</param>  
        /// <param name="LeftString">左边文本</param>  
        /// <param name="RightString">右边文本</param>  
        /// <returns>找到返回取出的中间文本,没找到返回空</returns> 
        public static string GetMiddleString(string SumString, string LeftString, string RightString)
        {
            if (string.IsNullOrEmpty(SumString)) return "";
            if (string.IsNullOrEmpty(LeftString)) return "";
            if (string.IsNullOrEmpty(RightString)) return "";

            int LeftIndex = SumString.IndexOf(LeftString);
            if (LeftIndex == -1) return "";
            LeftIndex = LeftIndex + LeftString.Length;
            int RightIndex = SumString.IndexOf(RightString, LeftIndex);
            if (RightIndex == -1) return "";
            return SumString.Substring(LeftIndex, RightIndex - LeftIndex);
        }

 

C# 取文本中间

标签:

原文地址:http://www.cnblogs.com/xiaomihu/p/5819767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!