#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, , searchStr.Length, StringComparison.Ordinal) > -)
{
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) > -)
{
result = s.Substring(, s.Length - searchStr.Length);
}
return result;
}
catch (Exception e)
{
return result;
}
}
#endregion
  

上海.NET招聘:

郑州.NET招聘:

深圳.NET招聘:

C#替换字符串起始/结尾指定的字符串的更多相关文章

  1. 如何用原生js替换字符串中的某个字符(或字符串)为指定的字符串?

    <html> <head><title>我的第一个 HTML 页面</title></head><script type=" ...

  2. 笔记:iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)(别人的代码直接复制过来的,我脸皮有点厚)

    NSString* str=@"hello";//存在代码区,不可变 NSLog(@"%@",str); //1.[字符串插入] NSMutableString ...

  3. iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)

    NSString* str=@"hello";//存在代码区,不可变 NSLog(@"%@",str); //1.[字符串插入] NSMutableString ...

  4. replace() MySQL批量替换指定字段字符串

    mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...

  5. 用变量替换指定的字符串,sed: -e 表达式 #1, 字符 29: “s”的未知选项

    在shell脚本里,使用sed,然后用变量替换指定的字符串,一直出现这个错误:但是单独运行在外面可以 把分隔符/替换成#就可以: sed "s#revision=.*#revision=$s ...

  6. 替换{0}为指定的字符串(MessageFormat)

    package com.text; import java.text.MessageFormat; /**替换{0}为指定的字符串*/ public class MessageFormatTest { ...

  7. Java 将指定字符串连接到此字符串的结尾 concat()

    Java 手册 concat public String concat(String str) 将指定字符串连接到此字符串的结尾. 如果参数字符串的长度为 0,则返回此 String 对象.否则,创建 ...

  8. mysql函数之七:replace() MySQL批量替换指定字段字符串

    mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...

  9. 字串符相关 split() 字串符分隔 substring() 提取字符串 substr()提取指定数目的字符 parseInt() 函数可解析一个字符串,并返回一个整数。

    split() 方法将字符串分割为字符串数组,并返回此数组. stringObject.split(separator,limit) 我们将按照不同的方式来分割字符串: 使用指定符号分割字符串,代码如 ...

随机推荐

  1. ThreadLocal,静态变量,实例变量,局部变量的线程安全

    之前都是业务层次开发,现在公司进行的网络编程,一下子要了解太多java底层的东西并进行应用,我现在边学习边应用.由于知识能力有限,在上次发博客时出现了一个小小的纰漏,而这个纰漏被细心的博友发现了. 首 ...

  2. Django分页器及自定义分页器

    Django的分页器 view from django.shortcuts import render,HttpResponse # Create your views here. from app0 ...

  3. HBase里的官方Java API

    见 https://hbase.apache.org/apidocs/index.html

  4. 【转】SQL SERVER 主体,已同步

    转自郭大侠博客:  https://www.cnblogs.com/gered/p/10601202.html 目录 SQL SERVER 基于数据库镜像的主从同步... 1 1.概念... 2 1. ...

  5. hibernate_07_单表操作_增删改操作

    首先,创建类对象 package com.imooc.hibernate; public class Address { private String postcode; //邮编 private S ...

  6. asp.net 正则表达式 得到图片url 得到汉字

    //取图片            MatchCollection   matchs   =   Regex.Matches(AskText,@"<img\s[^> ]*src=( ...

  7. Deutsch lernen (03)

    1. das Gewerbe, - 行业 Was ist Ihr Gewerbe? Welches Gewerbe treibt er? treiben - trieb - getrieben  从事 ...

  8. monad - the Category hierachy

    reading the "The Typeclassopedia" by Brent Yorgey in Monad.Reader#13 ,and found that " ...

  9. 【转】虚拟化(四):vsphere高可用功能前提-共享存储搭建

    vsphere高级功能HA.DRS.FT等,都需要有共享存储环境,即多台esxi主机同时连接一个共享存储,这样在新建虚拟机时,可以指定把虚拟磁盘保存在共享存储上,便于虚拟机在各个主机之间“飘移”. 常 ...

  10. 阿里云直播鉴权java代码示例

    段时间公司需要做直播服务,所以就研究了一下阿里云的直播,在直播里面,最重要的就是url的鉴权操作(验证推流或者拉流的有效性),在网上找了很多代码,都没有发现java的demo,所以就写篇播客记录一下, ...