StringTokenizers....
hey everybody,
i have a hashmap which has several words/phrases in it (each element is not neccesarily a single word..it might be two++). for example, lets pretend the term: "computer system" is in the HashMap.
i have to open an HTML file (which has some text in it) and everytime the phrase "computer system" turns up, i have to turn it into a hyperlink...for example, if the input.html file had:
'The computer system is very old.'
I would create a new file called updated.html that says
'The computer system is very old' --> however, computer system would be a hyperlink.
i've coded quite a bit, but i'm faced with a problem.
after storing the input.html document in a stringbuffer, i do the following:
private void checkLinks(String src_)
{
StringTokenizer st = new StringTokenizer(src_, " "); // Use space as delimiter
int tokens = st.countTokens(); // Number of tokens in document
StringBuffer dest = new StringBuffer(" "); // Temporary storage
for(int i=0; i<tokens; i++) // go through all tokens
{
String token = st.nextToken();
if(data.wordBank.containsKey(token)) // Token found in HashMap, add link
{
String linkDest = (String)data.wordBank.get(token);
dest.append("><a href=\"").append(linkDest).append("\">").append(token).append("</a> ");
}
else
{
dest.append(token).append(" ");
}
}
save(dest.toString()); // Save to disk
}
this code works well -- however, only if the terms in the HashMap are single words..."computer system" would not be detected. is there a good way i can modify my code to permit this?
any feedback is appreciated.
thanks,
-jin

