Important alert: (current site time 7/16/2013 6:55:16 AM EDT)
 

VB icon

MuLot Bolding Search

Email
Submitted on: 4/17/2003 10:32:40 AM
By: Le MuLoT  
Level: Beginner
User Rating: Unrated
Compatibility: Cold Fusion MX
Views: 14528
author picture
(About the author)
 
     Just looking à Google.com. When you do a search, the word that you looking for is in bold in all the results. You must call the function like this: #MuLoT_BoldingSearch("word search", "in this text")# example: #MuLoT_BoldingSearch("look this", "eh look at this!!!")#
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: MuLot Bolding Search
// Description:Just looking à Google.com. When you do a search, the word that you looking for is in bold in all the results.
You must call the function like this:
#MuLoT_BoldingSearch("word search", "in this text")#
example:
#MuLoT_BoldingSearch("look this", "eh look at this!!!")#
// By: Le MuLoT
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=75&lngWId=9//for details.//**************************************

<cfscript>
		/***************************************************************************************\
		*	Auteur:	Frédéric Gauthier-Boutin													*
		*	Date:	10 avril 2003																*
		*	Description:																		*
		*		Fonction servant à mettre en évidence les mots recherchés dans un texte			*
		*																						*
 		*		Arguments :																		*
		*			SearchFor	=>	Mot(s) recherché(s) dans le texte							*
		*			From		=>	Texte dans lequel nous recherchons							*
		*							le ou les mots contenus dans SearchFor						*
		*																						*
		*		Arguments Optionnels :															*
		*			StartTag	=>	Début du tag qui sera inséré devant							*
		*							chaque mot recherchés (par défaut, met en gras)				*
		*			EndTag		=>	Fin du tag inséré devant le mot recherchés par StartTag		*	
		*			Exclude		=>	Contient une liste de mots à exclure						*	
		*							(séparer les mots par des espaces)							*
		*	Version: #2.0																		*
		\***************************************************************************************/
		function MuLoT_BoldingSearch(SearchFor, From){ 
			/*	Définition et initialisation de mes variables et des arguments optionels
				REM:	Déclaration obligatoire de toutes les variables au début de la fonction.
						Sans cela, une erreur de type << No top level page was found >> est déclanchée.
			*/
			var iCtr = 2; 			//Curseur déterminant le début du mot
			var iFin = 1; 			//Curseur déterminant la fin du mot
			var strTotal = From; 	//Contiendra le texte final avec les nouvelles balises
			var strMot = ""; 		//Contiendra le mot venant d'être isolé
			var iLongueurMot = 0;	//Contiendra la longueur du mot isolé
			var iLongueur = 0;		//Contiendra le nombre de caractères dans la chaîne de mots recherchés
			var StartTag = "<b>";	//Met en gras le mot recherché
			var EndTag = "</b>"; 	//Ferme le tag du début
			var Exclude = " ou et ";//Nous excluons certains mots clés pour Verity
			//Vérification si nous avons reçu des arguments supplémentaires
				
			if(ArrayLen(arguments) GTE 5)
				Exclude = Exclude & arguments[5];
			
			if(ArrayLen(arguments) GTE 4)
				EndTag = arguments[4];
			if(ArrayLen(arguments) GTE 3) 
				StartTag = arguments[3];
				
			//Enlève les espaces avant et après le ou les mots
			SearchFor = " " & trim(SearchFor);
						
			/*
				J'ai ajouter un espace devant afin de faciliter l'entrée de la chaîne de caractères
			 	dans ma boucle. Autrement, il m'aurait fallu des conditions spéciales pour le tout
			 	1er caractère. C'est aussi pour cette raison, que iCtr débute à 2 et non à 1.
			 
			 	* Vous n'avez qu'à étudier la structure du 1er if pour comprendre. *
			*/
			//Vérification s'il y a des mots à rechercher
			if (SearchFor NEQ " ") {
				
				//Détermine le nombre de caractères à parcourir (+1 pour terminer le dernier mot)
				iLongueur = len(SearchFor) + 1;
				
				//Boucle parcourrant tous les caractères de la chaîne de mots recherchés
				while ( iCtr LT iLongueur )
				
					/*
						Ici, il y aurait 2 vérifications à faire pour détecter le début
						d'un mot sans l'ajout d'un espace devant SearchFor (comme expliqué plus haut) :
							1)	La première lettre de la chaîne correspond certainement au début
								d'un mot, car on a enlèvé les espaces avant et après et
								et on a vérifié que la chaîne n'était pas vide.	
							2)	Quand je tombe sur un espace et que le prochain caractère est une lettre,
								c'est le début d'un mot à coup sûr.
						
						Dans notre cas, ayant ajouté un espace, nous ne devons vérifier que l'étape #2.
					*/
					if ( Mid(SearchFor, iCtr, 1) NEQ " " AND Mid(SearchFor, iCtr - 1, 1) EQ " " ) {
																			
						//Recherche d'un espace pour trouver la fin du mot
						//+1 car iCtr est déjà sur un caractère
						iFin = Find(" ", SearchFor, iCtr + 1);
						
						//Vérification si s'était le dernier mot de la liste de mots
						if ( iFin EQ 0 )
							iFin = iLongueur;
						
						//Obtention de la longueur du mot
						iLongueurMot = iFin - iCtr;
						
						//Extraction du mot
						strMot = Mid (SearchFor, iCtr, iFin - iCtr);
						
						//Vérification si c'est un mot à exclure
						if ( FindNoCase(strMot, Exclude) EQ 0 ) 
							//Met les nouvelles balises entre le mot
						 strTotal = ReplaceNoCase(strTotal, strMot, StartTag & strMot & EndTag, "ALL");
								
						/*
							Incrémentation du compteur jusqu'à la fin de la longueur du mot
							afin de passer au suivant et continuer la recherche.
							
							+1 car nous devons continuer la recherche après le mot
						*/
						iCtr = iCtr + iLongueurMot + 1;
						
					} else
						//Incrémentation du compteur, afin de passer au caractère suivant
						iCtr = iCtr + 1;
		
				/*** FIN DE LA BOUCLE ***/
				
				//Retourne le texte contenant toutes les nouvelles balises
			 return strTotal;
			} else
			
				//Aucuns mots à rechercher
				return SearchFor;
		}</cfscript>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.