• C# 截取两个字符串中间的子字符串


    /// <summary>
    /// 截取中间字符
    /// </summary>
    /// <param name="text">全字符串</param>
    /// <param name="start">开始字符串 </param>
    /// <param name="end">结束字符串 </param>
    /// <returns></returns>
    public static string Substring(string text,string start,string end)
    {
        Regex regex = new Regex("(?<=(" + start + "))[.\s\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline);
        return regex.Match(text).Value;
    }

    /// <summary>
            /// 包含多个,截取中间字符,返回数组
            /// </summary>
            /// <param name="text">全字符串</param>
            /// <param name="start">开始字符串 </param>
            /// <param name="end">结束字符串 </param>
            /// <returns></returns>
            public string[] GetAllMatchedItems(string text, string start, string end)
            {
                Regex reg = new Regex("(?<=(" + start + "))[.\s\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline);
                int count = reg.Matches(text).Count;
                string[] Items = new string[count];
                for (int i = 0; i < count; i++) {
                    Items[i] = reg.Matches(text)[i].Value;
                }
                return Items;
            }
    
    
    

     /// <summary>
            /// 获取双引号间的字符串
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            internal string GetBetweenDoubleQuoteString(string str) {
                Regex regex = new Regex(""[^"]*"");
                return regex.Match(str).Value.Replace(""", "");
            }

     
  • 相关阅读:
    常用工具-notepad++打开大文件卡死现象
    ORM框架之EntityFramework
    System.Data.Entity 无法引用的问题
    js 数组、对象转json 以及json转 数组、对象
    js中(function(){xxx})();写法解析以及function与!感叹号
    js 里面call()的使用
    Javascript继承机制的设计思想
    JS中let和var的区别
    利用JS实现图片的缓存
    实例详述FOR XML PATH用法
  • 原文地址:https://www.cnblogs.com/Wonderful-Life/p/9831483.html
Copyright © 2020-2023  润新知