且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查找两个已知值之间的字符串

更新时间:2022-11-13 12:43:04

无需解决方案正则表达式:

Solution without need of regular expression:

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