请求大神,C#如何截取字符串中指定字符之间的部分 按指定字符串分割 一分为二 c# 去除字符串中的某个已知字符...

string stra = "abcdefghijk";
string strtempa = "c";
string strtempb = "j";
//我们要求c---g之间的字符串,也就是:defghi
//求得strtempa 和 strtempb 出现的位置:
int IndexofA = stra.IndexOf(strtempa);
int IndexofB = stra.IndexOf(strtempb);
string Ru = stra.Substring(IndexofA + 1, IndexofB - IndexofA -1);
Console.WriteLine("Ru = " + Ru); //----这就是你要的结果
Console.ReadLine();

 

 

 

string stra = "abcdeeeefeeeghijk";
var sArray = stra.Split(new string[] { "ef" }, StringSplitOptions.RemoveEmptyEntries); //一分为二  abcdeee    eeeghijk
Console.WriteLine();

 

 

c# 去除字符串中的某个已知字符

关键字:Replace;字符串中去除某个字符,可以理解成把想要去除的字符换成"";

去除已知字符:

public static void Main(string[] args)
{
去除字符串中的“b”
string str = "abc123";
string result = str.Replace("b","");
Console.WriteLine(result);
}
结果:ac123



转载于:https://www.cnblogs.com/cjm123/p/9547052.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值