删除这些值之间的内容<>< /> [英] Delete what is between these values <></>

查看:75
本文介绍了删除这些值之间的内容<>< />的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除值标记之间的输出,但我要删除。我只想删除作为我的表的数据中的值标记。能帮我删除这些值吗?请记住,那些输出不是硬编码的,用户只是输入了这些值,所以每次加载表格时我都要删除标签之间的那些输出。



I want to delete the output between the value tags but am falling to do so. i only want to delete the value tag that is within the data which is my table. can you please help me delete those values. keep it in mind that those output are not hard-coded,the user just entered those values, so every time i load the form i want to delete those output between the tags.

<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>





i试过这个,但我没有指定数据中的值标签,这是我的表。看下面我的编码;





i tried this, but am failing to specify the value tags that are within the data which is my table. see my coding below;

string text = File.ReadAllText(outputFilePath);
                text = DeleteBetween1(text, "<value>", "</value>");







public string DeleteBetween1(string STR, string FirstString, string LastString)
       {
           string regularExpressionPattern1 = "<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;
       }

推荐答案

美好的一天,



如果我理解正确,您要删除< value>< / value>文本中的标记。



使用函数DeleteBetween1(...),您需要更改正则表达式模式以包含两个标记及其间的任何内容。



Good day,

If I understood correctly, you want to remove the "<value></value>" tag from within the text.

Using your Function DeleteBetween1(...), you will need to change the Regular Expression pattern to include both tags and whatever is in between.

string regularExpressionPattern1 = "<value>.*</value>";



应查找符合条件的任何文本



您还需要将RegexOptions更改为None或Multiline


That should look for any text matching your criteria

You would also need to change your RegexOptions to either None, or Multiline

Regex regex = new Regex(regularExpressionPattern1, RegexOptions.None | RegexOptions.Multiline);



这应该会在所有出现的条件中找到文本。



对于替换部件,您只需要在每个匹配的循环内执行此操作


That should find all occurrences of your criteria in the text.

For the replacement part you only need to execute this inside the loop for each Match

STR = STR.Replace(m.Value, "");





希望它能解决你的问题。



完整代码:



Hope it solves your issue.

Complete Code :

public static string DeleteBetween1(string STR, string FirstString, string LastString)
{
    string regularExpressionPattern1 = "<value>.*</value>";
    Regex regex = new Regex(regularExpressionPattern1, RegexOptions.None | RegexOptions.Multiline);
    MatchCollection collection = regex.Matches(STR.ToString());
    foreach (Match m in collection)
    {
        STR = STR.Replace(m.Value, "");
    }
    return STR;
}


您好,



您可以使用一种方法删除价值标签。

按照下面的代码行可以帮助你。



Hi,

You can use one method to delete the value tag.
Follow the below line of code which can help you.

string xx = @"<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>";
            var xd = XElement.Parse(xx);
            Response.Write(xx.Replace(xd.Element("value").ToString(),""));





这里我使用String值作为输入。根据您的要求,您可以更改。



谢谢

Sisir Patro



Here I have used the String value as input. Based on your requirement you can change.

Thanks
Sisir Patro


这篇关于删除这些值之间的内容&lt;&gt;&lt; /&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆