Search and Replace by Meraj SamiThis one came about helping one of the users on one of the message board. He had asearch page from which the users on his site, guess what, could do the search. He wantedto highlight the search criteria in his result from the database. For example if theuser's search string was "the" and one of the string i ... Search and Replace by Meraj SamiThis one came about helping one of the users on one of the message board. He had asearch page from which the users on his site, guess what, could do the search. He wantedto highlight the search criteria in his result from the database. For example if theuser's search string was "the" and one of the string in the search resultcontained (remember, it is an example) "whatever summer winter tHe weather whetherTHE the The tHe thE thermometer thermometerthe", every occurrence of "the"should be highlighted. If you do it with replace function, for example, | <% searchString="the" replaceWith="<FONT COLOR='red'><b>" & searchString & "</b></font>" strOriginal="whatever summer winter tHe weather whether THE the The tHe thE thermometer thermometerthe" strOriginal=Replace(strOriginal,searchString,replaceWith,1,-1,1) %> then you can highlight every occurrence of the search string in the result, but in the process lose the case of the search string -- all the occurrence of "the" now will be in lower case. To avoid that I came up with this little function that will highlight all the occurrence of the search string in the result and also maintain the original case. | | <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER"> Function stringReplace(strSearchWithin,strSearchFor) Dim lngStartingPosition Dim lngFoundPosition Dim strReplaced 'Set the start position lngStartingPosition=1 lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1) do while lngFoundPosition > 0 'found strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPosition-lngStartingPosition) & "<font color='red'>" & mid(strSearchWithin,lngFoundPosition,len(strSearchFor)) & "</font>" lngStartingPosition=lngFoundPosition+len(strSearchFor) lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1) Loop stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one End Function </SCRIPT> <% OPTION EXPLICIT Dim strSearchWithin,strSearchFor strSearchWithin="whatever summer winter tHe weather whether THE the The tHe thE thermometer thermometerthe" strSearchFor="the" Response.Write stringReplace(strSearchWithin,strSearchFor) %> | |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
| | | | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
| | | | As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
| | | | This paper is about the critical role that a discipline called integrated requirements management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrating, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way. FREE! Go There Now!
| | | | Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
| | | | Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
| | | | In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |