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) 我们将按照不同的方式来分割字符串: 使用指定符号分割字符串,代码如 ...
随机推荐
- Appium + python - automator定位操作
# coding:utf-8from appium import webdriverfrom time import sleep desired_caps = { 'platformName': 'A ...
- Django 创建新项目后要完成的几个步骤
首先,在过一遍创建新项目的步骤: -创建一个新项目 -建了数据库后要确定自己是用 mysql数据库 还是用 sqlite3数据库 -如果是mysql数据库,那一堆配置 -如果是sqlite3数据库, ...
- 离线安装 Rancher2.2.4 HA 集群
一.先决条件(所有主机执行) 1.1 基础设置 1.安装基础软件 yum install -y vim net-tools wget lrzsz 2.防火墙 sed -i 's/SELINUX=enf ...
- Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook解决方法
有时候电脑中进行Java -version相关的操作时,会出现Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook提示信息,尽管这些提示信息不影响JDK的正常使 ...
- 自己写的_top、_parent以及对iframe和frameset的理解
iframe可以写在<body>标签里,如<body><iframe src="xxx" name="xxx" style=&q ...
- MySQL学习笔记之右连接
MySQL的右连接 #右连接,以右表为基表 select course.stuid,course.stuname,sex,course,city from class1 right join cour ...
- 35个jquery小技巧
1. 禁止右键点击 ? 1 2 3 4 5 $(document).ready(function(){ $(document).bind("contextmenu",fun ...
- spring定时任务Cron时间设定
直接举例: 0 10 0 * *?分别对应的是 秒 分 时 日 月 周 年 秒(0–59)分钟(0–59)小时(0–23)日(1–31)月(1–12或JAN–DEC)周(1–7或SUN–SAT)年(1 ...
- 【JAVA练习】- 给定精度求圆周率π
给定一个精度求圆周率π的近似值 给定公式:π/4=1-1/3+1/5-1/7+1/9-... public static void main(String[] args) { System.out.p ...
- 1C课程笔记分享_StudyJams_2017
课程1C 概述 课程1C是创建一个生日贺卡应用的实践课程,所以本篇笔记分享主要记录个人的实践过程,此外分享一些比较零散的知识点. Drawable文件夹 Drawable文件夹是Android项目统一 ...