我需要能够提取字符串2标签之间,例如:从00002, morenonxmldata<标签1> 0002< /标签1> morenonxmldata
I need to be able to extract a string between 2 tags for example: "00002" from "morenonxmldata<tag1>0002</tag1>morenonxmldata
"
在使用C#和.NET 3.5。
In using C# and .NET 3.5.
A 正则表达式
- 免费的解决方案:
A RegEx
-free solution:
string ExtractString(string s, string tag) {
// You should check for errors in real-world code, omitted for brevity
var startTag = "<" + tag + ">";
int startIndex = s.IndexOf(startTag) + startTag.Length;
int endIndex = s.IndexOf("</" + tag + ">", startIndex);
return s.Substring(startIndex, endIndex - startIndex);
}