[英]Extract Values between Open/Close Tags
I have many records from a database that have a field with the following appended:我有许多来自数据库的记录,这些记录有一个附加了以下内容的字段:
...blah blah. <edited><editID>variable-text-here</editID><editDate>variable-date-here</editDate></edited>
In my C# code I want to get the variable-text and variable-date out of each, to use within my program.在我的 C# 代码中,我想从中获取变量文本和变量日期,以便在我的程序中使用。
What would be the best/most efficient way of doing this?最好/最有效的方法是什么?
I would use a regular expression, something like:我会使用正则表达式,例如:
Match result = System.Text.RegularExpressions.Regex.Match(inputString,"<editID>.*</editID>");
Match result = System.Text.RegularExpressions.Regex.Match(inputString,"<editDate>.*</editDate>");
Hope it helps!希望能帮助到你!
<editID>[\s\S]*?</editID>
Or deal it as xml.或按 xml 处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.