C# - How To Highlight Complete Words With Keywords With Regexp

Feb 26, 2010

I have a longer text and some keywords. I want to highlight these keywords in my text. That is no problem with this code:

private static string HighlightKeywords2(string keywords, string text)
{
// Swap out the ,<space> for pipes and add the braces
Regex r = new Regex(@", ?");
keywords = "(" + r.Replace(keywords, @"|") + ")";
// Get ready to replace the keywords
r = new Regex(keywords, RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Do the replace
return r.Replace(text, new MatchEvaluator(MatchEval2));
}
private static string MatchEval2(Match match)
{
if (match.Groups[1].Success)
{
return "<b>" + match.ToString() + "</b>";
}
return ""; //no match
}

But when the word"tournament" is in the text and the keyword "tour" it becomes <b>tour</b>nament. I want to it to highlight the complete word: <b>tournament</b>.

View 1 Replies


Similar Messages:

Forms Data Controls :: How To Highlight Words In A Repeater When Match The Searched Words

Nov 17, 2010

I have a pretty basic search feature on a site that queries a sqldb with a sqldarasource, and then displays the results on a page, in a panel within a Repeater. I'd like to figure out if it's possible to somehow highlight the words the user searched on as they are displayed in the search results. The code below is my repeater. Do you know of any way to manipulate the Title or Description if the words in it's body match the words searched?

<asp:Panel
ID="pnlExperience"
runat="server"
Height="500px"
ScrollBars="Auto">
[code]...

View 1 Replies

Need To Automatically Highlight The Keywords In The Text Box Using Code Behind C#?

Apr 29, 2010

I m retrieving a text from SQL DB based on the Search criteria i give and displaying in the Textbox in asp.net. I need to highlight the words given in the search criteria in the displayed text.

For example : If i give "need" all the word "need" in textbox that is retrieved and displayed should be highlight in yellow color.

View 1 Replies

Forms Data Controls :: Highlight Search Keywords In Gridview?

Jul 12, 2010

I build a serach function just using SelectCommand and SelectParameters, i.e.

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:mprojectConnectionString %>"
SelectCommand="SELECT * FROM [publication] WHERE ((([character] LIKE '%' + @character + '%') AND ([type] = @type))
OR(([f11623] LIKE '%' + @f11623 + '%') AND ([type] = @type))
OR (([f1character] LIKE '%' + @f1character + '%') AND ([type] = @type))
OR(([nortonoxfordnumber] LIKE '%' + @nortonoxfordnumber + '%') AND ([type] = @type))
OR (([nortonoxfordtext] LIKE '%' + @nortonoxfordtext + '%') AND ([type] = @type)))">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="character" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="f11623" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="f1character"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="nortonoxfordnumber"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="nortonoxfordtext"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="DropDownList1" Name="type"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

I am also using a dropdown box and a textbox for people to search within a particular area from the dropdown list.

Now, I would like to be able to highlight the keywords in my gridview table. I searched around on the Internet and found a lot of samples, but they are all related to the Gridview <templates>, however, I am using <BoundField> and sqlDataSource.

I just cound not figure out how can I add this highlight function to my current search function?

View 4 Replies

DataSource Controls :: Auto Complete - Get Keywords From Full Text Catalog?

May 30, 2010

This is my first time using autocomplete. I have everything up and running, but I want to return a list of more relevent keywords or phrases from my full text catalog, or the table that I search against. I have no idea where to start as far as my getcompletionlist goes.

So If I type in knee
a list appears
kneepads

here's my getCompletionList
Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim items As New List(Of String)
Dim myConnectionString As String
myConnectionString = GetSQLConnString()
Dim mySelectQuery As String = "SELECT ShortDescription FROM ProductInfo WHERE FREETEXT(ShortDescription, @prefixText) OR FREETEXT(LongDescription, @prefixText) OR FREETEXT(ProductHTML, @prefixText) OR FREETEXT(PartNumber, @prefixText) ORDER BY RANK()
OVER (Order BY PartNumber, ShortDescription, LongDescription)"

[Code]....

View 2 Replies

Data Controls :: Highlight Searched Words In GridView

Apr 27, 2016

How to highlight searched words in gridview when serach performed on multiple column, i have 5 column in gridview and i perform search through text box and a button and bind gridview with searched record on all 5 column...

How to highlight searched keyword on all 5 column...

View 1 Replies

Web Forms :: Highlight And Replace Words In After Search (but Not In Html Sytax)?

Nov 18, 2010

I have everything working as I wanted except that when I search for the keyword and if the keyword is in an URL, it messes up the link. For instance if I search for music, the keyword in the URL is replaced by

[Code]....

so in the end the URL is like this:

[Code]....

How do I avoid replacing the keyword if the keyword is an URL? Someone mentioned using IndexOf but I'm not sure.

[Code]....

View 3 Replies

Forms Data Controls :: Highlight Key Words In A Datagrid From A Search Box?

Nov 4, 2010

Is there a way to highlight key words in a datagrid from a search box?

View 8 Replies

Installation :: Windows Installer Keywords / List Of All The Keywords Available In A Windows Installer Like [TargetDir] And [ProductVersion]?

Mar 7, 2011

Can anyone guide me to a website where I can see the list of all the keywords available in a windows installer like [TargetDir] and [ProductVersion].

Can anyone also show me a very detailed tutorial of customizing the windows installer?

View 1 Replies

Regexp - Converting From JS Match To C#

Feb 4, 2010

This is probably a simple one for C# people :-) I have this regular expression in javascript:

strVar = strVar.replace(/(specificattribute=)"s*([^"]+?)s*"/g, '$1"$2"');

It replaces leading and trailing spaces inside a specific attribute's value, globally (as per this example page: [URL]). I need to do the same on a string in C#, but when trying the above, the syntax checker chokes at the regExp. So I need the equivalent line of the above in C#.

View 8 Replies

Regex - Validating Email Address With Regexp?

May 1, 2010

When validating an email address with the regex validation component, an additional RequiredFieldValidator must be added to ensure there is a value present.

I've mostly taken care of this with a CustomFieldValidator, and taking care of this with Javascript.

View 1 Replies

C# - Selected Row Highlight Not Moving When Gridview Is Sorted / Sorts Properly But The Highlight Stays On The Same Line?

Nov 5, 2010

I have an ASP.net gridview on a webform where user's can select a row. When they select it, the row is highlighted yellow. The problem is that when I sort the table, it sorts properly but the highlight stays on the same line. The data all moves, but the highlight stays put.

how I can make the highlight stay with the data?

View 3 Replies

Can Add Keywords For Seo In Every HTML Tag

Mar 20, 2011

Can I add Keywords for Seo in every HTML tag?

View 7 Replies

Search More Then 2 Keywords In C#.net?

Dec 17, 2010

i want to Search more then 2 item with one TEXTBOX field using with , Eg. item1,item2.

Result should be shown for both in one gridview i am using SP with one Parameter.

View 2 Replies

Dynamically Add Keywords And Title To A Webpage?

Mar 29, 2010

How can one dynamically add Keywords & Title to a page. I had created one table called Meta table for URL rewritting in which in addition to url details, i had stored keywords & title of Product page. I had done URL Rewriting of the page but I just couldn't make out how can one associate a Product page with Keywords & title at runtime.

View 11 Replies

Generate Meta Keywords From Database?

Mar 19, 2010

Ok my website I built for fun effeduptxt.com I am trying to take all the posts that are displayed and have the keywords for the page be auto generated at page load.

Now I know how to add keywords from code behind I just never tried to scrape the data in the database for what would be the best keywords to use.

Has anyone ever done this and or know where something like this is on the web.

I can create the SQL Query and the C# code how to determine what is a bogus word that should not be included such as I could count how many times each word is shown and go for the most common words as the keywords but that would include words like "And", "Or", "It" etc... and that would not be good.

I have no problem with studying more detail about it and expect to do so I just need to get set onto the right path....

View 3 Replies

Localization :: Difference Between Keywords Like Internationalization?

Apr 13, 2010

I was trying to figure out difference between keywords like Internationalization, Localization etc. and publish paper on best practice. But I got confused even on basic definitions which are so varying on internet. Following are 2 theories I found, so far. please advise which is correct?

Theory - 1

Globalization is a plan tom implement Internationalization and Localization

Internationalization - It is not implementing multiple languages, but it include activities so that Application can be made to support multi-languages and cultures in future. Like doing activities such as:

- Using nVarchar instead of varchar
- Avoiding Satic text and instead storing data to display in resource/text files

Localization - This is actual process when an internationalized application is updated with multiple languages and localization settings. For example, continuing with Internationalziation I would say activities like:

- Formatting Date, Numbers, Currency etc. using CurrentCulture class
- Adding text for different languages in files (we created during internationalization process) and customizing UI
- Using CurrentUICulture class for language conversions
- Providing user an interface to set their preferences
- Regional Settings in Administrative Panel of Windows is actually Localization

Theory - 2
Globalization - same as above Internationalization - First part of aforesaid Localization definition - Number. Currency etc. formatting (General Tab in Regional Settings)

Localization - Second part of aforesaid Localization definition - Language Translation (Language Tab in Regional Settings)

QUESTION: Which one is correct theory? If both above are wrong, what is right?

View 4 Replies

Search Engine Support Keywords?

Jun 14, 2010

this is naresh.i have some query.in google search engine while typeing any letter based on letter some support keyword is getting.

View 8 Replies

Web Forms :: How To Extract Keywords From Text And Where Collect Them

Mar 14, 2011

1- how to extract keywords from text and where collect them?

2- how to find search engine keyword that redirect to my site?

3- best solution for collect keywords, tag and how work wtih them and where save them?

View 9 Replies

MVC :: Implement Dynamic Meta Keywords And Description In 2

Jul 22, 2010

what is best tutorial to implement dynamic title, meta keywords and description in a mvc2 application.

View 1 Replies

Web Forms :: Finding Keywords In Text And Linking To Products?

Dec 5, 2010

I want to find the keywords/products in text block and link them to my products.

Is a algorithm or sample code somewhere i can start with?

View 4 Replies

How To Show Keywords And A Search Box Under Site's Google Results

Jan 20, 2010

I saw on the google when search "code project", some keywords and a text field and a button to search that google has generated for "code project" keyword also for "manchester university" in the same way.

How is it possible to show key words and text field/button for our website on google? As it shows for "code project" and "manchester university" etc.

visit google and search "manchester university" u'll see:

StudentNet Job Opportunities
PostGraduate StaffNet
etc..
and
textfield/ and a button

I want this kind of result for my site from Google!!

View 2 Replies

To Create A Search Textbox For Users To Enter A Few Keywords In?

Feb 19, 2010

I want to create a seach textbox for users to enter a few keywords in ,..and then my sql query will display the results......( basically a little search engine for my website)Ok so im thinking of using the Containstable with ranking on how close these keywords are to eachother... so the closer the keywords are to each other... the higher their ranking will be.... but I also want to seach for these keywords in 4 columns in one Datatable how can I do this

View 7 Replies

Forms Data Controls :: Declare And Set Keywords In Gridview?

Feb 5, 2010

I have the following code:

[Code]....

As you can see, I have two variables @total and @euclidDist, and I have declaring them and defining them using DECLARE and SET respectively. This query works in VB and MSSQL and returns the required results, however when I try to great a Gridview, and I paste the above query in the query builder, it asks me to input the values to @total and @euclidDist, ie it ignores the fact that I already defined them in the statement itself...how do I get around this?

View 1 Replies

Web Forms :: Display Value In META Keywords And Description Tag From Database

May 24, 2013

 i have seen your article to display value in title and keyword tag from database. then i want to know to display value in META Description tag from database . 

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved