0

I have a string like

                     address
                     424 G UT <br>

So when I use

      string trimstr= node5.InnerHtml.Trim();

This only aligns the first line not the second line. Also
also gets printed in the html . How can I remove html tags and remove white spaces using HTML agility pack.

Kshitiz
  • 35
  • 2
  • 5

1 Answers1

1

modify your c# code with this

here html

<div id="node5" runat="server">
                 address
                 424 G UT <br>
</div>
<div>
    <asp:Button ID="btmGetDivdetails" runat="server" Text="getDivdetails" 
        onclick="btmGetDivdetails_Click" />

</div>

here c# code on the button click

protected void btmGetDivdetails_Click(object sender, EventArgs e)
{
  string trimstr = node5.InnerHtml;
  trimstr = trimstr.Replace("\r\n<br>", "").Replace("\r", "").Replace("\n", "").Trim();
  if (trimstr.Contains("<br>"))
  {
      trimstr =  trimstr.Replace("<br>", "");
  }
  List<char> result = trimstr.ToList();
  result.RemoveAll(c => c == ' ');
  string finalresult = new string(result.ToArray());
}

now the finalresult is "address424GUT"

Chandan Kumar
  • 4,570
  • 4
  • 42
  • 62
  • Hey guyz I used the trim function in c# am getting the text in random format like this (lots of spaces and line breaks ) . – Kshitiz Dec 22 '13 at 08:37