jinen_k
August 6, 2001, 12:51 am
hey this is my first post...the website/community seems great. i have a question for the java heads:
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 have coded the majority of this...however, my code only changes SINGLE words..
After I read in the input.html into a StringBuffer...I do this:
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
}
does anybody know how i can modify this code to make it change terms that are two words (or more?).
i hope this was clear...if not, please let me know or e-mail me!
thanks ...
jinen@hiphopsite.com
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 have coded the majority of this...however, my code only changes SINGLE words..
After I read in the input.html into a StringBuffer...I do this:
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
}
does anybody know how i can modify this code to make it change terms that are two words (or more?).
i hope this was clear...if not, please let me know or e-mail me!
thanks ...
jinen@hiphopsite.com