Capturing strings between stopwords



private string StringBetween(string beginTag, string endTag, string texteToParse)
{
System.Collections.Specialized.StringCollection coll = StringsBetween(beginTag, endTag, texteToParse);
if (coll.Count == 0) return "";
else return coll[0];
}
private System.Collections.Specialized.StringCollection StringsBetween(string beginTag, string endTag, string texteToParse)
{
System.Collections.Specialized.StringCollection result = new System.Collections.Specialized.StringCollection();
int pos1, pos2;
pos1 = 0;
pos2 = -1;
pos1 = texteToParse.IndexOf(beginTag);
while (pos1 > -1)
{
pos2 = texteToParse.IndexOf(endTag, pos1 + beginTag.Length);
if (pos2 > -1)
{
result.Add(texteToParse.Substring(pos1 + beginTag.Length, pos2 - (pos1 + beginTag.Length)));
pos1 = texteToParse.IndexOf(beginTag, pos2 + endTag.Length);

}
else
pos1 = -1;

}
return result;
}

No comments: