my problem is that im unable to find a word in a string. the strings are in a file and then placed in nodes. i have to go through each token in each node to find the 'word'.
but my code doesn't work. how can i make my code to understand that word: "night" == token in node: "night." .
help please
CODE
import java.util.*;
import java.io.*;
import java.util.StringTokenizer;
class edit
{
class Node
{
Node next;
String text;
}
private Node head;
boolean openB=false;
Node m=new Node();
int i;
Scanner myScanner=new Scanner(System.in);
System.out.printl
public void menu() throws Exception
{
System.out.println("Enter option --> ");
String cmd=myScanner.next();
if(cmd.equals("open"))
{
linecount=0;
System.out.print("Enter file name : ");
fname=myScanner.next();
openB=open(fname);
}
else if(cmd.equals("find"))
{
System.out.print("Text to find? ");
String textFind=myScanner.next();
System.out.println("ontop of method call: "+textFind);
find(textFind);
}
else
break;
}
public void find(String s)
{
m=head;
i=1;
String temp, line;
System.out.print("Found on line(s): ");
while(m!=null)
{
if(i==1)
line=head.text;
else
line=m.text;
StringTokenizer tokenizer=new StringTokenizer(line);
while(tokenizer.hasMoreTokens())
{
temp=tokenizer.nextToken();
if( temp.equals(s))
{ System.out.print(" "+i); }
}
m=m.next;
i++;
}
}
}