c # - Error when trying to Replace a string

3

Good People,

I have the following problem:

When trying to replace of a string (of a Literal Control ), using the following code, the value of the same does not change.

 MyControl.Text.Replace("id=\"KP\"", "id=\"KPC\"");

However, if I try to change only the value of id (as the following code shows), it works perfectly.

 MyControl.Text.Replace("KP", "KPC");

Q: I have to use the id no replace, because the text of literal contains more than once the reference to the value of id .

[EDIT] - I leave here an excerpt of literal for better understanding (it's repetitive)

<li><a class="fancybox" title="BK-001" href="imgpeles/KP-01.jpg" rel="fancybox">
    <img alt="" src="imgpeles/KP-01_t.jpg" width="55" height="55" id="KP-01"><br>
    BK-001</a>
</li>
    
asked by anonymous 31.08.2018 / 11:27

1 answer

4

Below is a solution:

string teste = System.IO.File.ReadAllText("c:\arquivo.txt");          

teste = teste.Replace("id=\"KP", "id=\"KPC");

Note: The file .txt contained your HTML.

    
31.08.2018 / 12:41