zoukankan      html  css  js  c++  java
  • asp.net c#截取指定字符串函数

    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

    }

  • 相关阅读:
    QT *.pri 语法学习
    qt 的相对路径说法
    openwrt 时间更新
    openwrt network 初始化
    在线配置热加载配置 go-kratos.dev 监听key 通过atomic.Value支持自动热加载
    Monkey patching
    UDP flood UDP Port Denial-of-Service Attack
    一例 Go 编译器代码优化 bug 定位和修复解析
    t
    golang 网络编程之如何正确关闭tcp连接以及管理它的生命周期 socket
  • 原文地址:https://www.cnblogs.com/liufei88866/p/2497395.html
Copyright © 2011-2022 走看看