#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. golang单点推送

    package main import ( "encoding/json" "flag" "fmt" "log" &qu ...

  2. ACM_名字的价值

    名字的价值 Time Limit: 2000/1000ms (Java/Others) Problem Description: 集训终于开始了,参加集训的人很多,也就有很多名字,集训组织者发现了一件 ...

  3. D - Vanya and Fence

    Problem description Vanya and his friends are walking along the fence of height h and they do not wa ...

  4. Oracle快速收集AWR的方案

    记一种方便的awr收集方法,该脚本可以按小时收集目标时段的awr 素材:awr_generate.sql(具体脚本内容请见本文末尾) (1)将awr_generate.sql置于数据库服务器本地路径, ...

  5. C# 多线程系列(一)

    线程是怎样工作的 1.多线程由一个线程调度器来进行内部管理,一个功能是CLR常常委托给操做系统. 一个线程调度器确保所有激活的线程在执行期间被合适的分配,等待或者阻塞的线程(比如,一个独占锁或者等待用 ...

  6. sql的padleft

    /* SELECT dbo.fn_PadLeft('8', '0', 6) */ create function fn_PadLeft(@num nvarchar(16),@paddingChar c ...

  7. 基于mybatis向oracle中插入数据的性能对比

    数据库表结构: 逐条插入sql语句: <insert id="insert" parameterType="com.Structure"> INSE ...

  8. python排序sorted与sort比较 (转)

    Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列. sorted(iterable,key=None,revers ...

  9. 【剑指Offer】8、跳台阶

      题目描述:   一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果).   解题思路:   首先考虑最简单的情况,如果只有1级台阶, ...

  10. CSS学习笔记之基本介绍

    1.简介 层叠样式表(Cascading Style Sheets,CSS)允许我们把样式设置存储在文件中,从而将内容与表现分离 当同一个 HTML 元素被不只一个样式定义时,最终的样式确定顺序如下( ...