zoukankan      html  css  js  c++  java
  • C# 匹配开始字符和结束字符

    /// <summary>
            /// 获得字符串中开始和结束字符串
            /// </summary>
            /// <param name="str">字符串</param>
            /// <param name="s">开始</param>
            /// <param name="e">结束</param>
            /// <returns></returns>
            public static List<string> GetValue(string str, string s, string e)
            {
                return Regex.Matches(str, "[.\s\S]*?(?<=(" + s + "))[.\s\S]*?(?<=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline)
                   .Cast<Match>()
            .Select(t => t.Value.LastIndexOf(s) == -1 ? t.Value :  t.Value.Substring(t.Value.LastIndexOf(s))).ToList();
            }
         private void GetAllDataStr(string DataValue)
            {
                try
                {
                    string regx = "(?<=(01))[.\s\S]*?(?=(04))";
                    if (string.IsNullOrWhiteSpace(DataValue))
                        return;
                    bool isMatch = Regex.IsMatch(DataValue, regx);
                    if (!isMatch)
                        return;
                    MatchCollection matchCol = Regex.Matches(DataValue, regx);
                    string[] result = new string[matchCol.Count];
                    if (matchCol.Count > 0)
                    {
                        for (int i = 0; i < matchCol.Count; i++)
                        {
                            result[i] = "01" + matchCol[i].Value + "04";
    
                            StrToASCII(result[i]);
                        }
                    }
                }
                catch(Exception ex)
                {
                    WriteLog.Write(ex.Message);
                }
            }
  • 相关阅读:
    PAT 甲级 1132 Cut Integer (20 分)
    AcWing 7.混合背包问题
    AcWing 9. 分组背包问题
    AcWing 5. 多重背包问题 II
    AcWing 3. 完全背包问题
    AcWing 4. 多重背包问题
    AcWing 2. 01背包问题
    AcWing 875. 快速幂
    AcWing 874. 筛法求欧拉函数
    AcWing 873. 欧拉函数
  • 原文地址:https://www.cnblogs.com/Duriyya/p/13631894.html
Copyright © 2011-2022 走看看