1 public class ContactSearchHighlight{ 2 public string srchArg{get;set;} 3 public List<Contact> lstcontact {get;set;} 4 public ContactSearchHighlight(){ 5 lstContact = [select id, name, details__c from contact where details__c != null]; 6 } 7 8 public PageReference search(){ 9 string srchPhrase = '%' + srchArg + '%'; 10 lstContact = [select id, name, details__c from contact where details__c like :srchPhrase]; 11 12 for(Contact cnt: lstContact){ 13 cnt.details__c = highlightPhrase(cnt.details__c, srchArg); 14 } 15 16 return null; 17 } 18 19 public string highlightPhrase(string mainString, string phrase){ 20 mainString = mainString.toLowerCase().replaceAll(phrase.toLowerCase(), '<span class="highlight_word">' + phrase + '</span>'); 21 return mainString; 22 } 23 24 }