【发布时间】:2015-02-17 10:05:32
【问题描述】:
我已经问过这个问题,但没有回答正确。我想删除值标签之间的输出,但我不想这样做。我只想删除我的表数据中的值标签。你能帮我删除这些值吗?请记住,这些输出不是硬编码的,用户只是输入了这些值,所以每次我加载表单时,我都想删除标签之间的那些输出。
<data name="CurrentSelectedUser_Label" xml:space="preserve">
<value>Current selected record:</value>
<comment>[Font]Bold[/Font][DateStamp]2015/01/01 00:00:00[/DateStamp][Comment] this is a comment.!![/Comment]</comment>
</data>
<data name="FinEnrolment_Exit_Button" xml:space="preserve">
<value>Exit Finger Enrolment</value>
<comment>[Font]Regular[/Font][DateStamp]2014/012/01 00:00:00[/DateStamp] [Comment] this is a comment.!![/Comment]</comment>
</data>
我试过这个,但我没有指定我的表格数据中的值标签。请参阅下面的编码;
string text = File.ReadAllText(outputFilePath);
text = DeleteBetween1(text, "<value>", "</value>");
public string DeleteBetween1(string STR, string FirstString, string LastString)
{
string regularExpressionPattern1 = "<value(.*?)</value>";
Regex regex = new Regex(regularExpressionPattern1, RegexOptions.Singleline);
MatchCollection collection = regex.Matches(STR.ToString());
var val = string.Empty;
foreach (Match m in collection)
{
val = m.Groups[1].Value;
STR = STR.Replace(val, "");
}
STR = STR.Replace(val, "");
return STR;
}
【问题讨论】: