请求大神,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



posted @ 2018-08-28 11:26  ~雨落忧伤~  阅读(1639)  评论(0编辑  收藏  举报