Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

bolding searcch keyword very urgent

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My problem is i have to bold a search term which client enteers can somebody plz give me the source code for this
i have an example for this
lets say client enters java hand & the search returns java hand server programming java
only hand & java should be bold .
This is my reqt this is very urgent \can somebody plz help me out of this,
Pavithra
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is a mixture of HTML and Java programming. Assuming you have a long String that may contain a recognized word, the general flow is:
1. use the String indexOf method to see if one of the recognized words is present.
a. Not present - display the String and quit
b. present, go to 2
2. using the index determined in 1, cut the String in two parts, display the first part, send the HTML code to start bolding, send the recognized word, send the end bolding, cut the String after the recognized word.
3. If the String is now empty, quit, if not go back to 1 with the shorter String.
You can do this with a small method called recursively or with regular looping constructs. It gets more complex if you also have to recognize words in various cases.
Bill

------------------
author of:
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done this before. So you can do the smae thing as your requirement is also same as mine. (This is a JSP)
You can do th same thing is java also
<%@ page import="java.util.*" %>
<% String desc=("This is the string to be tokenized");%>
<% String key=request.getParameter("search key");%>
<% StringTokenizer st = new StringTokenizer(desc); %>

<% while (st.hasMoreTokens()) { %>
<% String word=st.nextToken(); %>
<% int avail = word.indexOf(key);%>
<% if(key.equalsIgnoreCase(word)){%>
<font face="Tahoma" size="1" color="blue"><%=word%></font>
<%}else{%>
<% if (avail != -1) {%>
<font face="Tahoma" size="1" color="blue"><%=word%></font>
<% }else{%>
<font face="Tahoma" size="1"><%=word%></font>
<%}%>
<%}%>
<%}%>

Originally posted by pavi kavi:
Hi,
My problem is i have to bold a search term which client enteers can somebody plz give me the source code for this
i have an example for this
lets say client enters java hand & the search returns java hand server programming java
only hand & java should be bold .
This is my reqt this is very urgent \can somebody plz help me out of this,
Pavithra



[This message has been edited by janaki samaraweera (edited June 24, 2001).]
 
janaki samaraweera
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just try this..I suppose you want to "bold" different words in different locations in the same string..
see whether this is ok.

import java.util.*;
public class testGarbage {

public static void main(String args[]) {
StringTokenizer st = new StringTokenizer("This string to be bold");
String key1="string";
String key2="bold";

while(st.hasMoreTokens()){
String word=st.nextToken();
int avail_1 = word.indexOf(key1);
int avail_2 = word.indexOf(key2);

if(key1.equalsIgnoreCase(word)){
System.out.println(" bold string 1 " + word);
}
if(key2.equalsIgnoreCase(word)){
System.out.println(" bold string 2 " + word);
}
}
}
}

Originally posted by janaki samaraweera:
I have done this before. So you can do the smae thing as your requirement is also same as mine. (This is a JSP)
You can do th same thing is java also
<%@ page import="java.util.*" %>
<% String desc=("This is the string to be tokenized");%>
<% String key=request.getParameter("search key");%>
<% StringTokenizer st = new StringTokenizer(desc); %>

<% while (st.hasMoreTokens()) { %>
<% String word=st.nextToken(); %>
<% int avail = word.indexOf(key);%>
<% if(key.equalsIgnoreCase(word)){%>
<font face="Tahoma" size="1" color="blue"><%=word%></font>
<%}else{%>
<% if (avail != -1) {%>
<font face="Tahoma" size="1" color="blue"><%=word%></font>
<% }else{%>
<font face="Tahoma" size="1"><%=word%></font>
<%}%>
<%}%>
<%}%>

[This message has been edited by janaki samaraweera (edited June 24, 2001).]


 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only problem with the StringTokenizer approach is that it is confused by trailing punctuation. However, you can use the form of StringTokenizer constructor that takes a list of separators AND returns the separators:
st = new StringTokenizer( str, " .,;:\\\"'?/", true )
That way you can spit out the separators in the right place.
Bill
 
pavi kavi
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for help i have done it only a line i have to add since i am doing a search i dont how many iam geeting evrytime
but once aghin thank u
PAvithra

Originally posted by William Brogden:
The only problem with the StringTokenizer approach is that it is confused by trailing punctuation. However, you can use the form of StringTokenizer constructor that takes a list of separators AND returns the separators:
st = new StringTokenizer( str, " .,;:\\\"'?/", true )
That way you can spit out the separators in the right place.
Bill


 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic