For Example:

java is an object oriented language. it has many feature including 1.1 robust 1.2 inheritance. java is a interesting language.

I need output as follows:

java is an object oriented language.
it has many feature including 1.1 robust 1.2 inheritance.
java is a interesting language.

Note:
I need to extract a sentence from a document.

For Example:

java is an object oriented language. it has many feature including 1.1 robust 1.2 inheritance. java is a interesting language.

I need output as follows:

java is an object oriented language.
it has many feature including 1.1 robust 1.2 inheritance.
java is a interesting language.

Note:
I need to extract a sentence from a document.

strtokeize with '.' symbol...

so it will be

java is an object oriented language.
it has many feature including 1
.1 robust 1
.2 inheritance.
java is a interesting language.

when you get each string like this..

so you check if else condition to rearrange this statement...

plz mark solved previous post String array to object...it will encourage me...

Comments
Thats not the way

strtokeize with '.' symbol...
so it will be
java is an object oriented language.
it has many feature including 1
.1 robust 1
.2 inheritance.
java is a interesting language.
when you get each string like this..
so you check if else condition to rearrange this statement...

Why not on ". " (period and space character) then ? It would avoid all the trouble for one thing.

plz mark solved previous post String array to object...it will encourage me...

Does seeing your "SolvedThreads" counter go up the only thing that encourages you ? So that you keep on repeating the same thing after almost every post. Whatever happened to the good feeling of having helped someone solve something.

@OP: To split sentences you would need to check for either of the two things. First ". " (period & space character) as mentioned above and then the period and the new line character for sentences starting on new lines or paragraph as these would not be necessarily be having the space character after the period character.

Edited 6 Years Ago by verruckt24: n/a

Comments
I agree.
offending by making fun of my word "SolvedThreads"

Does seeing your "SolvedThreads" counter go up the only thing that encourages you ? So that you keep on repeating the same thing after almost every post. Whatever happened to the good feeling of having helped someone solve something.

i don't know you pursuing me and put negative marks..

is really giving pleasant to you?

i am not technical expert...

i learning through by analyzing other problems...

just i asked for "Mark it solved" to know whether i am useful or not...

you may giant in technical but i am not...

what i know that i suggested to others that may helpful or may not be..

so plz make it correct if i done wrong...

otherwise it will not be good always for you...

so be careful before put negative mark as unnecessary...

i don't know you pursuing me and put negative marks..
is really giving pleasant to you?
i am ot technical expert...
i learning through by analyzing other problems...
just i asked for "Mark it solved" to know whether i am useful or not...
you may giant in technical but i am not...
what i know that i suggested to others that may helpful or may not be..
so plz make it correct if i done wrong...
otherwise it will not be good always for you...
so be careful before put negative mark as unnecessary...

I am not asking you to be a technical expert, I don't expect you to be, but what we and the OP expects is you not guiding him incorrectly. Whether you do it on purpose or by accident is irrelevant. In this thread I found your advice wrong to which I replied correcting you. That post was down voted by you know who. Here too you seemed to be leading him incorrectly and I tried to advice him the correct way. Again this post was down voted by... you-know-who. You could go back and check on both posts and try to figure out who was the one giving the wrong advice, who was the one correcting the wrong advice and who, if at all, should have been down-voted. But that is ofcourse if you can actually figure out the right from the wrong.

What is that that you are upset about that someone corrects the mistakes left by you ? Or that you don't get credit for giving incorrect advice ?

PS: And the next time you write something atleast use full legible sentences and some good grammar so that we atleast understand what are cribbing about.

Edited 6 Years Ago by verruckt24: n/a

hi....
I am new to dani web. I don't know how to put marks in dani web. But after using your code only i got the output.... thank you.......

hi....
I am new to dani web. I don't know how to put marks in dani web. But after using your code only i got the output.... thank you.......

you solved it then see Text ("Mark It Solved") at the bottom of the thread...

And where in your post did you use this word could you show us ?

the word used by you...

sorry for my poor English...

Hi,
You suggest me to use if else condition. If you give more details regarding this, it will help me..

Hi,
You suggest me to use if else condition. If you give more details regarding this, it will help me..

correct me if am wrong...

if your sentence seems to be variable then it is impossible i think..

because stringtokenizer using tokens to delimit the string...

hi,
No, i am not going to store a string in a variable. I am going to store a string in object.

For example :

StringTokenizer st = new StringTokenizer("I born on 21.02.1995. So, now my age is 15.", ".");

I will get output as :

I born on 21
02
1995
So, now my age is 15.

But i want output as :
I born on 21.02.1995.
So, now my age is 15.

Note :

So after storing string into st object. How to use if else condition to get exact output.

Well as you have noticed the command given, brakes the input into smaller pieces depending on the argument:

StringTokenizer st = new StringTokenizer("I born on 21.02.1995. So, now my age is 15.", ".");

So all you have to do is figure out what to use in order to break the above sentence in two:

StringTokenizer st = new StringTokenizer("[B]I born on 21.02.1995[/B]. [B]So, now my age is 15.[/B]", "??????");

Notice that the above are not separated by a '.' but by a '. '
If the above is unique in your sentence then you can use that.

Also it is better to use the split method from now on:

String s = "I born on 21.02.1995. So, now my age is 15.";
String [] tokens = s.split(" ");
for (int i=0;i<tokens.length;i++) {
   System.out.println(tokens[i]);
}

You can use the above and in order to get these 2 sentences:

I born on 21.02.1995.
So, now my age is 15.

You can concatenate the first elements of the array into 1 String and then the rest into the other.

Hi,
What you told was right, we can use split method. But why i am not using split method was i need to access all the StringTokenizer method.
So, if you give more idea on stringtokenizer it will be help full to me.

My previous post already states what to use as a delimiter.

Also what are the methods you want to use of that class that cannot be done with the split method? I am not suggesting that using the StringTokenizer would be wrong. I was just asking

Ok fine.. Now i am trying with stringTokenizer only. If i get the output i will inform to you and if u get inform to me........

Forget about stringTokenizer. Even SUN recommends against using it in favor of split. Here is (tested) working solution...

public class SplitTest{

	public static void main(String[] args) throws Exception {

	/** According to Sun's website at: 
		http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html
		
		"StringTokenizer is a legacy class that is retained for compatibility reasons 
		although its use is discouraged in new code. It is recommended that anyone 
		seeking this functionality use the split method of String or the 
		java.util.regex package instead."

      ===============
		
		So, even Sun (Oracle) recommends using the String.split() static method.
		
		Keep in mind that your token will be consumed by split,
		so if you are concerned, you will have to replace it. 
		If you are looking for special chars, like decimal points, make sure to escape them.
		
		Here is a working solution...
		*/
		
		String origToken = ".";
		String s = "I born on 21.02.1995. So, now my age is 15.";
		
		// Chop up the string based on the split token (in this case a special one!)
		String [] tokens = s.split("\\.\\ "); // Notice the padding here.. 		
		for (int i=0;i<tokens.length;i++) {
			// Since the token is consumed in split process, we must re-attach it
			// It's called the ternary operator..google it
			System.out.println((tokens[i].endsWith(origToken)) ? tokens[i] : tokens[i] + origToken);
		}
		
	}
}

-Patrick

This article has been dead for over six months. Start a new discussion instead.