.NET Replace() doesn´t work

53 views Asked by At

Hi i´m parsing aspx file to XML and i have this code:

if (lineLower.StartsWith("</asp:content>")) || (lineLower.StartsWith("</asp:Content>") && lineLower.EndsWith(">")))
                                    {
                                        temp += line.Replace(line, " ");
                                    }

But this temp += line.Replace(line, " "); will just add a space before < /asp:content> instead of replacing it byt space.

Do i need to use different syntax?

2

There are 2 answers

0
Guillaume Munsch On

First, you have this

if (lineLower.StartsWith("</asp:content>"))

You're closing your if too soon

Try this

if (lineLower.StartsWith("</asp:content>") || (lineLower.StartsWith("</asp:Content>") && lineLower.EndsWith(">"))
                                {
                                    temp += line.Replace(line, " ");
                                }
0
Guy Levin On

You coded it way too complicated

Just do this:

if (line.ToLower().StartsWith("</asp:content>") && line.EndsWith(">")))
{
    temp += " ";
}

Not even sure if you need this part : line.EndsWith(">")