Hi
You need to use Regular expression to replace the content with highlight color and change text.
Refer below example.
HTML
<asp:HiddenField ID="hfWord" runat="server" />
<asp:HiddenField ID="hfHTML" runat="server" />
<iframe id="frmDisplay" runat="server" frameborder="0" height="500"></iframe>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var iframeHtml = $("#hfHTML").val();
$('#frmDisplay').contents().find('body').html(iframeHtml);
});
</script>
Namespaces
using System.IO;
using System.Text.RegularExpressions;
Code
protected void Page_Load(object sender, EventArgs e)
{
//Session.Add("Logintype", Session["new"].ToString());
if (!this.IsPostBack)
{
hfWord.Value = "Airplane";
getpa();
}
}
public void getpa()
{
string pstext = "Airplane";
string patext = "ASPSnippets";
string html = File.ReadAllText(Server.MapPath("~/HTML.txt"));
string searchText = HttpUtility.HtmlEncode(pstext);
string title = patext;
string newstring = "<span style='background-color:yellow'><a title='" + title + "'>" + pstext + "</a></span>";
html = Regex.Replace(html, pstext, delegate (Match match) { return newstring; }, RegexOptions.IgnoreCase);
hfHTML.Value = html;
}
Screenshot