asp.net - How to get search result from the original string after searching with C# -



asp.net - How to get search result from the original string after searching with C# -

what i've tried here can show file path contents string in textbox1.text cannot , show string in file.

private void search_click(object sender, eventargs e) { string[] filepaths = directory.getfiles(@"c:\users\abcdq\downloads\documents\", "*.pdf", searchoption.alldirectories); (int = 0; < filepaths.length; i++) { string settext = gettextfrompdf(filepaths[i]); if (settext.toupper().contains(textbox1.text.toupper())) { messagebox.show(filepaths[i]); } } }

for example: in account.pdf, has:

new users? new users, need fill in form right of page next information: back upwards reference – back upwards contract number e.g. dm1234 or rh1234. company name – needs exact name know match back upwards reference. display name – name, automatically filled in when utilize of forms in site. email & email confirm – email address, become username. password – password consisting of @ to the lowest degree 6 characters (letters, numbers, , symbols).

when search email confirm result must homecoming me string email confirm not email confirm. more that, looking way homecoming string has more characters in left , right side string email & email confirm – email address.

if want know where in string text you're looking found, utilize string.indexof(). example:

string searchtext = textbox1.text; int index = settext.indexof(searchtext, stringcomparison.ordinalignorecase); if (index >= 0) { string foundtext = settext.substring(index, searchtext.length); }

for more complex searches, can utilize system.text.regularexpressions.regex class. returns match objects, in turn contain group objects describe text matched.

edit:

to accommodate returning context around found text, utilize alternative:

string searchtext = textbox1.text; int prefix = 5, postfix = 5; 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); }

naturally can initialize prefix , postfix like; hard-coded them here sake of example.

c# asp.net search-engine

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -