Deleting between the tags it is not deleting

∥☆過路亽.° 提交于 2020-01-07 07:02:00

问题


I have asked on how to delete between values between the tags and i got solution of which i had to modify to meet my needs, but now the problem is it doesn't delete the values between the tags and i debug to see the error but no error was found. when i check the file that is been created i can still see the values inside the tags. please help me

under new button which copies the file

            XmlReadMode omode = oDataSet.ReadXml(PathSelection);
            for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
            {
                string comment = oDataSet.Tables["data"].Rows[i][2].ToString();

                string font = DeleteBetween(comment, "[Font]", "[/Font]");
                string datestamp = DeleteBetween(comment, "[DateStamp]", "[/DateStamp]");
                string commentVal = DeleteBetween(comment, "[Comment]", "[/Comment]");

                string[] row = new string[] 
                {
                    oDataSet.Tables["data"].Rows[i][0].ToString(),
                    oDataSet.Tables["data"].Rows[i][1].ToString(),
                    font, 
                    datestamp, 
                    commentVal
                };
                File.Copy(txtInputfile.Text, txtInputfile.Text.Replace("string-en.resx", "string-lan.resx"));
                Gridview_Output.Rows.Add(row);
           }

Function

     public string DeleteBetween(string STR, string FirstString, string LastString)
    {
        string regularExpressionPattern1 = @"(?:\" + FirstString + @")([^[]+)\[\/" + LastString;
        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;
        }
        return val;
    }

来源:https://stackoverflow.com/questions/28451833/deleting-between-the-tags-it-is-not-deleting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!