I want to delete what is between these values <value><value/>

Posted by STS under C# on 2/17/2015 | Points: 10 | Views : 376 | Status : [Member] | Replies : 1
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 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;
}




Responses

Posted by: Lcoimbatorer on: 6/10/2015 [Member] Starter | Points: 25

Up
0
Down
Hi,

Please use the below code snippet to achieve this

static void Main(string[] args)
{

string outputFilePath = "S:\\For1\\xml.txt";
string text = File.ReadAllText(outputFilePath);
text = DeleteBetween1(text, "<value>", "</value>");
}
public static 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;
}

//lcoimbat

STS, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response