Friday 15 April 2011

asp.net - How to add tag to the text after searching in WebBrowser with C# -



asp.net - How to add <b> tag to the text after searching in WebBrowser with C# -

what i've tried can output total text search. more that, add together <b> tag each keyword after searching image below.

the textbox has lower characters tran thi dao. however, here add together <b> tag result tran thi dao.

private string getbodytext() { stringbuilder strb = new stringbuilder(); string[] filepaths = directory.getfiles(@"\\rsc-app2k8\applications\rsc_hr_documents\", "*.pdf", searchoption.alldirectories); (int = 0; < filepaths.length; i++) { string settext = gettextfrompdf(filepaths[i]).replace("\r\n", " ").replace("\n", " ").replace("\r", " ").replace("\t", " "); string searchtext = tbsearch.text; int prefix = 50, postfix = 50; int index = settext.indexof(searchtext, stringcomparison.ordinalignorecase); if (index >= 0) { string foundtext = settext.substring(index, searchtext.length); int contextstart = math.max(0, index - prefix); int contextlength = math.min(settext.length - contextstart, searchtext.length + prefix + postfix); string contexttext = settext.substring(contextstart, contextlength); string files = path.getfilename(filepaths[i]); //messagebox.show(contexttext); strb.appendformat("<img src='" + pdficon + "' /> <a href='{0}'>{1}</a></br><b>{2}</b> {3}<br></br>", filepaths[i], files, foundtext, contexttext); } } homecoming strb.tostring(); }

how using regex solve problem? can search while ignoring case, , replace search term in original format <b> tags.

for example:

var searchterm = "bird"; var input = "hey bird flew on there. bird!"; var replaced = regex.replace(input, searchterm, match => { homecoming string.format("<b>{0}</b>", match); }, regexoptions.ignorecase);

this should give next result: hey <b>bird</b> flew on there. <b>bird</b>!

c# asp.net webbrowser-control

No comments:

Post a Comment