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

如何提取:“我/r是/vhi中国人/nr”,“人民/n英雄/n永/ad锤/v不朽/aj”。以上述两个字符串为例,第一个 如何提取 “/nr”之前的汉字,也就是中国人?
第二个 如何提取"/aj" 到“/v”之前的汉字,也就是不朽?
要求:/nr是代提取目标字符的标识,其他带有/的标注无所谓。
多谢!

第一题:
static void Main(string[] args)
{
string s = "我/r是/vhi中国人/nr";
string s1 = s.Substring(8,3);//从第8个字符开始取3个字符
Console.WriteLine(s1);
Console.ReadLine();
}
第二题:
static void Main(string[] args)
{
string s = "人民/n英雄/n永/ad锤/v不朽/aj";
string s1 = s.Substring(15,2);//从第15个字符开始取2个字符
Console.WriteLine(s1);
Console.ReadLine();
}追问

哎,要是这么简单,就不问百度了,肯定是索引位置不明确的情况,我已经实现了。用lastindexof ()和substring(),向前提取,再去字母
不过还是谢谢你的无私帮助

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-10-03
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();
第2个回答  2013-06-20
使用正则表达式正解

string t = "我/r是/vhi中国人/nr”,“人民/n英雄/n永/ad锤/v不朽/aj";
Regex reg = new Regex(@"^.+?锤/v(.+?)/aj$");
Match math = reg.Match(t);
if (math.Success)
{
Console.WriteLine(math.Groups[1].Value);
}

输出:不朽
第3个回答  2013-06-20
正则表达式
第4个回答  2013-06-20
split("/nr")?