Any Suggestions? Check out my problem.
Hi,
I have a short project...basically, I have a HashMap with several words in it. I also have a input html file with some text in it.
My project is that I have to make a new file...which has the same contents has the input file, BUT if any of the words from the Map shows up in the inputfile, I have to make those words hyperlinks.
For example, if the word "computer" is in the hashmap...and "The computer has 128 megs of RAM" is in the input.html file...i would create a new html file that says "The computer has 128 megs of RAM" -- BUT here 'computer' would be a hyperlink. (Thus, in the end, I would have a new HTML file which would have links to all words in the hashmap.)
I realllllllllllly need help here. I bet to many of you this is a simple problem!
-Jinen ... jtk9@cornell.edu
[847 byte] By [
jtk9] at [2007-9-26 2:42:25]

A question that comes to mind is...
What is/are the target(s) of the hyperlink ? The HTML syntax for e hyperlink is <a HREF="__target URL__">__label__</a>
The actual code to get this done should be pretty straight forward. However, you must answer the above question.
Considring a HashMap is to be used, chances are the key would be the word, value, well the actaully href source....
Addmittedly no master of effecient algorithms, quite far from it, Id recommend a StreamTokenizer which will parse individual words. A StringBuffer for the creation of the new file/ As each word is extracted you can call get(extractedWOrd) on the HashMap, test it for null....
if null, simply append the key... If not null, then well then, you cast the object returned to a String, and append that instead.... Very simple task I would think however the StreamTokenizer may bittle a little challenging if never used before... Ill dig around my computer a bit, I should have an example .......
Hope this helps,
J.Prisco
Yea you use the StreamTokenizer something like so
[code]
String temp = null;
StreamTokenizer tokenizer = new StreamTokenizer(new FileReader(someFileInstance));
while (tokenizer.nextToken() != StreamTokenizer.TT_EOF)
{
if(tokenizer.sval != null)
{
temp = (String)(myHashMap.get(tokenizer.sval))
if (temp == null)
myStrrBuff.append(tokenizer.sval+" ");
else
myStrBuff.append("<a HREF=\""+temp+"\"</a>");
}
}
this of course is just to give you an idea////