• C#替换字符串起始/结尾指定的字符串


         #region 替换字符串起始位置(开头)中指定的字符串
            /// <summary>  
            /// 替换字符串起始位置(开头)中指定的字符串  
            /// </summary>  
            /// <param name="s">源串</param>  
            /// <param name="searchStr">查找的串</param>  
            /// <param name="replaceStr">替换的目标串</param>  
            /// <returns></returns>  
            public static string CutStarStr(string s, string searchStr, string replaceStr)
            {
                var result = s;
                try
                {
                    if (string.IsNullOrEmpty(result))
                    {
                        return result;
                    }
                    if (s.Length < searchStr.Length)
                    {
                        return result;
                    }
                    if (s.IndexOf(searchStr, 0, searchStr.Length, StringComparison.Ordinal) > -1)
                    {
                        result = s.Substring(searchStr.Length);
                    }
                    return result;
                }
                catch (Exception e)
                {
                    return result;
                }
            }
            #endregion
    
            #region 替换字符串末尾位置中指定的字符串
            /// <summary>  
            /// 替换字符串末尾位置中指定的字符串  
            /// </summary>  
            /// <param name="s">源串</param>  
            /// <param name="searchStr">查找的串</param>  
            /// <param name="replaceStr">替换的目标串</param>  
            public static string CutEndStr(string s, string searchStr, string replaceStr)
            {
                var result = s;
                try
                {
                    if (string.IsNullOrEmpty(result))
                    {
                        return result;
                    }
                    if (s.Length < searchStr.Length)
                    {
                        return result;
                    }
                    if (s.IndexOf(searchStr, s.Length - searchStr.Length, searchStr.Length, StringComparison.Ordinal) > -1)
                    {
                        result = s.Substring(0, s.Length - searchStr.Length);
                    }
                    return result;
                }
                catch (Exception e)
                {
                    return result;
                }
            }
            #endregion
      

    上海.NET招聘:上海.NET招聘

    郑州.NET招聘:郑州.NET招聘

    深圳.NET招聘:深圳.NET招聘

  • 相关阅读:
    Kibana 地标图可视化
    Filebeat 日志收集
    ELK + Redis 日志收集 & HAProxy
    RAID 磁盘阵列
    Logstash 日志收集(补)
    ELK Stack 介绍 & Logstash 日志收集
    ElasticSearch 集群 & 数据备份 & 优化
    ElasticSearch 交互使用
    网络通信体系
    面向对象思想
  • 原文地址:https://www.cnblogs.com/romanticcrystal/p/6370261.html
Copyright © 2020-2023  润新知