2011-06-09 72 views
0

我从数据库中多条记录有与下面所附的一个领域:值提取

...blah blah. <edited><editID>variable-text-here</editID><editDate>variable-date-here</editDate></edited> 

在我的C#代码,我想要得到的可变文本和可变最新出在我的程序中使用。

这样做最好/最有效的方法是什么?

+0

如何使用... XML解析器? – 2011-06-09 14:04:00

+0

绝对使用XML解析器! – Jan 2011-06-10 10:05:32

回答

1

我会使用一个正则表达式,是这样的:

Match result = System.Text.RegularExpressions.Regex.Match(inputString,"<editID>.*</editID>"); 
Match result = System.Text.RegularExpressions.Regex.Match(inputString,"<editDate>.*</editDate>"); 

希望它能帮助!

+0

这看起来不错SoMoS - 虽然它也带回周围的标签 - 任何获得标签之间值的方法? – marcusstarnes 2011-06-09 14:31:32

+0

最简单的方法是将.Replace(“”,“”)作为结果的示例。 – 2011-06-09 15:51:08

0
<editID>[\s\S]*?</editID> 

或将其作为xml处理。