开发者

Extract Values between Open/Close Tags

开发者 https://www.devze.com 2023-03-12 05:33 出处:网络
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</ed

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 w开发者_高级运维ithin my program.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消