IT
posts - 548,comments - 58,trackbacks - 0

public string GetContent(string str, string start, string last, int n)
    {
       
if (str.ToLower().IndexOf(start.ToLower()) >= 0)
        {
           
if (str.ToLower().IndexOf(last.ToLower()) >= 0)
            {
               
switch (n)
                {
                   
//左右都截取(都取前面)(包含关键字)
                    case 1: str = str.Substring(str.ToLower().IndexOf(start.ToLower()), str.Length - str.ToLower().IndexOf(start.ToLower())); str = str.Substring(0, str.ToLower().IndexOf(last.ToLower()) + last.Length); break;
                   
//左右都截取(都取前面)(去除关键字)
                    case 2: str = str.Substring(str.ToLower().IndexOf(start.ToLower()) + start.Length, str.Length - str.ToLower().IndexOf(start.ToLower()) - start.Length); str = str.Substring(0, str.ToLower().IndexOf(last.ToLower())); break;
                   
//左右都截取(都取后面)(包含关键字)
                    case 3: str = str.Substring(str.ToLower().LastIndexOf(start.ToLower()), str.Length - str.ToLower().LastIndexOf(start.ToLower())); str = str.Substring(0, str.ToLower().LastIndexOf(last.ToLower()) + last.Length); break;
                   
//左右都截取(都取后面)(去除关键字)
                    case 4: str = str.Substring(str.ToLower().LastIndexOf(start.ToLower()) + start.Length, str.Length - str.ToLower().LastIndexOf(start.ToLower()) - start.Length); str = str.Substring(0, str.ToLower().LastIndexOf(last.ToLower())); break;
                   
//左右都截取(一前一后)(包含关键字)
                    case 5: str = str.Substring(str.ToLower().IndexOf(start.ToLower()), str.Length - str.ToLower().IndexOf(start.ToLower())); str = str.Substring(0, str.ToLower().LastIndexOf(last.ToLower()) + last.Length); break;
                   
//左右都截取(一前一后)(去除关键字)
                    case 6: str = str.Substring(str.ToLower().IndexOf(start.ToLower()) + start.Length, str.Length - str.ToLower().IndexOf(start.ToLower()) - start.Length); str = str.Substring(0, str.ToLower().LastIndexOf(last.ToLower())); break;
                   
default: str = ""; break;
                }
            }
           
else
            {
               
switch (n)
                {
                   
//只往左截取(取前面的)(包含关键字)
                    case 7: str = str.Substring(0, str.ToLower().IndexOf(start.ToLower()) + start.Length); break;
                   
//只往左截取(取前面的)(去除关键字)
                    case 8: str = str.Substring(0, str.ToLower().IndexOf(start.ToLower())); break;
                   
//只往左截取(取后面的)(包含关键字)
                    case 9: str = str.Substring(0, str.ToLower().LastIndexOf(start.ToLower()) + start.Length); break;
                   
//只往左截取(取后面的)(去除关键字)
                    case 10: str = str.Substring(0, str.ToLower().LastIndexOf(start.ToLower())); break;
                   
//只往右截取(取前面的)(包含关键字)
                    case 11: str = str.Substring(str.ToLower().IndexOf(start.ToLower()), str.Length - str.ToLower().IndexOf(start.ToLower())); break;
                   
//只往右截取(取前面的)(去除关键字)
                    case 12: str = str.Substring(str.ToLower().IndexOf(start.ToLower()) + start.Length, str.Length - str.ToLower().IndexOf(start.ToLower()) - start.Length); break;
                   
//只往右截取(取后面的)(包含关键字)
                    case 13: str = str.Substring(str.ToLower().LastIndexOf(start.ToLower()), str.Length - str.ToLower().LastIndexOf(start.ToLower())); break;
                   
//只往右截取(取后面的)(去除关键字)
                    case 14: str = str.Substring(str.ToLower().LastIndexOf(start.ToLower()) + start.Length, str.Length - str.ToLower().LastIndexOf(start.ToLower()) - start.Length); break;
                   
default: str = ""; break;
                }
            }
        }
       
else
        {
            str
= "无!";
        }
       
return str

}

posted on 2012-05-12 17:57 liufei 阅读(...) 评论(...) 编辑 收藏