• 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(""", "");
            }

     
  • 相关阅读:
    uvm_cookbook--sequences--wait for a signal
    Makefile目标文件搜索(VPATH和vpath
    git stash
    vuex-persist,解决vuex中的数据刷新页面之后丢失的问题
    element表格中的输入框有时会存在输入不上的情况
    简单 Linux 文件系统?
    Shell 脚本是什么?
    什么是BASH?
    如何规划一台 Linux 主机,步骤是怎样?
    什么是GUI?
  • 原文地址:https://www.cnblogs.com/Wonderful-Life/p/9831483.html
Copyright © 2020-2023  润新知