static void Main(string[] args)
{
string a = "";
Console.WriteLine(GetWantedString(a, 3, '>', 2, '<'));
Console.ReadLine();
}
private static string GetWantedString(string strToSplit, int cOneIndex, char cOne, int cTwoIndex, char cTwo)
{
int start = 0, indexOne = 0;
int end = 0, indexTwo = 0;
char[] strSplited = strToSplit.ToCharArray();
for (int i = 0; i < strSplited.Length; i++)
{
if (strSplited[i] == cOne)
{
start++;
if (start == cOneIndex) { indexOne = i; break; }
}
}
for (int i = 0; i < strSplited.Length; i++)
{
if (strSplited[i] == cTwo)
{
end++;
if (end == cTwoIndex) { indexTwo = i; break; }
}
}
if (indexOne != 0 && indexTwo != 0)
{
return strToSplit.Substring(Math.Min(indexOne, indexTwo)+1, Math.Abs(indexTwo - indexOne)-1);
}
return "没有找到";
}
//另外用正则表达式里的”零宽断言“也能实现
花生1
|
小虾三级
|园豆:872
|
2008-07-02 00:31