我从数据库中多条记录有与下面所附的一个领域:值提取
...blah blah. <edited><editID>variable-text-here</editID><editDate>variable-date-here</editDate></edited>
在我的C#代码,我想要得到的可变文本和可变最新出在我的程序中使用。
这样做最好/最有效的方法是什么?
我从数据库中多条记录有与下面所附的一个领域:值提取
...blah blah. <edited><editID>variable-text-here</editID><editDate>variable-date-here</editDate></edited>
在我的C#代码,我想要得到的可变文本和可变最新出在我的程序中使用。
这样做最好/最有效的方法是什么?
我会使用一个正则表达式,是这样的:
Match result = System.Text.RegularExpressions.Regex.Match(inputString,"<editID>.*</editID>");
Match result = System.Text.RegularExpressions.Regex.Match(inputString,"<editDate>.*</editDate>");
希望它能帮助!
这看起来不错SoMoS - 虽然它也带回周围的标签 - 任何获得标签之间值的方法? – marcusstarnes 2011-06-09 14:31:32
最简单的方法是将.Replace(“
<editID>[\s\S]*?</editID>
或将其作为xml处理。
我更喜欢使用XML解析。看到类似的问题在XML Parsing和Parsing a string in c#
如何使用... XML解析器? – 2011-06-09 14:04:00
绝对使用XML解析器! – Jan 2011-06-10 10:05:32