2015-06-09 92 views
0

嗨i'm解析aspx文件到XML和我有這樣的代碼:.NET替換()doesn't工作

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

但這溫度+ = line.Replace(行,「「);只會在</asp:content>之前添加一個空格,而不是將其替換爲空格。

我需要使用不同的語法嗎?

+1

究竟是你想達到什麼目的?你的IF邏輯看起來不穩定,根據LeZohan68的回答,這甚至不會編譯。 –

+0

您沒有使用實際XML解析器的任何原因,例如[XmlDocument類](https://msdn.microsoft.com/en-us/library/system.xml.xmldocument%28v=vs.110%29的.aspx)? – freefaller

+0

另外,不是'temp + = line.Replace(line,「」);'與'temp + =「」;「完全相同;''? – freefaller

回答

0

首先,你有這樣的

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

您要關閉if太快

試試這個

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

你編碼它太複雜

只是這樣做:

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

甚至不知道你是否需要這一部分:line.EndsWith(「>」)