您的位置:首页 > 编程语言 > C#

请求大神,C#如何截取字符串中指定字符之间的部分

2018-08-28 11:26 507 查看

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();

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐