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, , 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#替换字符串起始/结尾指定的字符串的更多相关文章
- 如何用原生js替换字符串中的某个字符(或字符串)为指定的字符串?
<html> <head><title>我的第一个 HTML 页面</title></head><script type=" ...
- 笔记:iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)(别人的代码直接复制过来的,我脸皮有点厚)
NSString* str=@"hello";//存在代码区,不可变 NSLog(@"%@",str); //1.[字符串插入] NSMutableString ...
- iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)
NSString* str=@"hello";//存在代码区,不可变 NSLog(@"%@",str); //1.[字符串插入] NSMutableString ...
- replace() MySQL批量替换指定字段字符串
mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...
- 用变量替换指定的字符串,sed: -e 表达式 #1, 字符 29: “s”的未知选项
在shell脚本里,使用sed,然后用变量替换指定的字符串,一直出现这个错误:但是单独运行在外面可以 把分隔符/替换成#就可以: sed "s#revision=.*#revision=$s ...
- 替换{0}为指定的字符串(MessageFormat)
package com.text; import java.text.MessageFormat; /**替换{0}为指定的字符串*/ public class MessageFormatTest { ...
- Java 将指定字符串连接到此字符串的结尾 concat()
Java 手册 concat public String concat(String str) 将指定字符串连接到此字符串的结尾. 如果参数字符串的长度为 0,则返回此 String 对象.否则,创建 ...
- mysql函数之七:replace() MySQL批量替换指定字段字符串
mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...
- 字串符相关 split() 字串符分隔 substring() 提取字符串 substr()提取指定数目的字符 parseInt() 函数可解析一个字符串,并返回一个整数。
split() 方法将字符串分割为字符串数组,并返回此数组. stringObject.split(separator,limit) 我们将按照不同的方式来分割字符串: 使用指定符号分割字符串,代码如 ...
随机推荐
- SpringAOP使用注解实现5种通知类型
spring aop的5种通知类型都有 Before前置通知 AfterReturning后置通知 Around环绕通知 AfterThrowing异常通知 After最终通知 首先创建接口和实现类 ...
- CALayer帧动画
CALayer帧动画 _sunLayer = [[CALayer alloc]init]; _sunLayer.contents = (id)[UIImage imageNamed:@"su ...
- itext 生成pdf文档 小结(自己备忘)
1.引入maven <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf& ...
- T - Amusing Joke(map)
Problem description So, the New Year holidays are over. Santa Claus and his colleagues can take a re ...
- 解决QQ未启用状态,QQ留言图标未启用
最近由于腾讯升级QQ一些东西,导致QQ图标成未启用状态:如图 解决方法,到腾讯此站点登陆一下即可, http://wp.qq.com/set.html 另外设置 没有保存按钮,如果选择完全公开,到自己 ...
- wpf,vb,位图剪裁的方法
‘ 貌似WPF对GDI+不提供支持,要达到剪裁图像的方法,可以使用image.clip,’不过clip只是对图片的一个遮挡拦截效果,并不改变本身的图片资源.‘下面的代码提供了剪裁图片资源的方法. Di ...
- .net core2.0 中使用aspectcore实现aop
一.新建一个web application项目 1.1.添加AspectCore.Extensions.DependencyInjection引用 二.实现AbstractInterceptorAtt ...
- SQLServer2008 使用BCP导入导出表数据
--先开启cmdshell EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'xp_c ...
- Android布局需要知道的基础知识
eclipse配置环境变量: 1.在 eclipse 中的 Window --> preferences --> Android(安装了ADT的前提下才能看到Android) --> ...
- Dynamics CRM查询实体共享给哪些人
在mscrm中,如果想查询一条记录共享给了哪些人,需要用到PrincipalObjectAccess 表,sql如下: select u.FullName,a.RC_name,sup.SystemUs ...