954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Extract the word from the text file using StringTokenizer

Hello,

Here I have a problem, I want to print the word after the Delimiters in a simple text file, but i cant able to do it also cant able to find a good example for that in a web.
So please if anyone help for this.

Vetha
Newbie Poster
7 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

What did you try?

thines01
Postaholic
Team Colleague
2,425 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

thank you,

actually i tried this code

public class word 
{
 	
	public static void main(String[] args)
	{
		String line=" ";
		int lineNo;
		
		try
		{
			FileReader fr= new FileReader("f:/parse1.txt");
			BufferedReader br=new BufferedReader(fr);
			for(lineNo = 1; lineNo <=4; lineNo++)
			{
				if(lineNo == 2 )
				{
				line = br.readLine();
				
				StringTokenizer st=new StringTokenizer(line,"-->");
				
				while(st.hasMoreTokens())
				{
					String s=st.nextToken();
					System.out.println(s);
				}
				
				}else
				{
					br.readLine();
				}
				
				
			}
			
		}catch(Exception e)
		{
			System.out.println(e);
		}
	}

}

My content in the text file is:

(FusionResultProcessor.java:145) - -------------------> Feed id: 0001 processing

SUCCEEDED. ProcessingTimeTook: 5 milliseconds.

got the output as,

(FusionResultProcessor.java:145)

Feed id: 0001 processing


I want to print only the feed id: xxx and i dont want to print the (fusion...). that is I want to print the data after the delimiter.

Vetha
Newbie Poster
7 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

What happens? Do you get errors? If so please copy and paste the full text here.
Otherwise show the programs output and explain what is wrong with it.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

hello,
I have already mentioned that what kind of output I am getting.

My question is how to print the data(for eg. Feed id:0001..) after the delimiter(">") and I dont want to print the text before the delimiter (">");

thank you,

Vetha
Newbie Poster
7 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 
What happens? Do you get errors? If so please copy and paste the full text here. Otherwise show the programs output and explain what is wrong with it.

Hello NormR1,

No I didnt get any errors, but I out put is

just like this


"(FusionResultProcessor.java:145)

Feed id: 0001 processing"

Vetha
Newbie Poster
7 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Can you make a test program with a String containing the delimiters and data that you want to print instead of requiring a separate test file. I assume that you do not need more than one line to show the problem.

Then we can all look at exactly the same code and data and see what the problem is.
For example:
line = "The String > to test < right here";

Where in your code do you determine whether the token you are getting is before or after the delimiter? I only see a println() to show all the tokens.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 
out put is just like this

What is wrong with that output? You need to explain what the output should look like.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 
What is wrong with that output? You need to explain what the output should look like.

hello,

I want to display only Feed id:0001 processing in my output window.

Vetha
Newbie Poster
7 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

If you want help, look at my suggestion about writing a test program that I described in an earlier post. Put everything in ONE file and post it.
Execute the program, show what it outputs and say what is wrong with the output.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

Hello,

Here I have a problem, I want to print the word after the Delimiters in a simple text file, but i cant able to do it also cant able to find a good example for that in a web. So please if anyone help for this.

Check this out: Text File Manipulation In Java
Text File Manipulation with Strings that Contain Spaces

dheaven
Newbie Poster
12 posts since Jan 2012
Reputation Points: 22
Solved Threads: 2
 

@dheaven:

Having looked at your previous posts, I'm assuming that you are either affiliated with the blog in consideration or own it. Posting self links is not recommended here and is seen as promotion. If you want to redirect users to your blog/help them, link your blog in the signature and refer them to it rather than having links as the post content.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: