File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Can i break the String to bits? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can i break the String to bits?" Watch "Can i break the String to bits?" New topic
Author

Can i break the String to bits?

Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128


what i am trying to do here, is to make it possible for the user to type 2 lines, and then say(or display) whether the string of the first sentence correspond to the string of the second sentence.

so for example:

first sentence:
i will go shopping

second sentence:
Tomorrow, i will go swiming.

" i will go" corresponds in the second sentence. so how can i make the program look for corresponding words, and identify them?

so far , i have written this. but i dont know how to finish.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Dmitri Makovetskiy wrote: ... " i will go" corresponds in the second sentence. so how can i make the program look for corresponding words, and identify them? ...

If you're looking for corresponding words, then I would not bother with individual chars. I would probably use String's split method to break the input into words, then write a method to compare sequences of these words using String's equals (or equalsIgnoreCase) method. Do not use ==.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

If you do it by character by character, then you'll end up with meshed code. Because, for example, in your first sentence, there is a char i, so you search for i in the second sentence, It's OK. But how do you put a space between the next word? And, for the second character w, there is a w in your first sentence's word Tomorrow. then?.....

It's better to go for checking word by word,,,,,


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
marc weber wrote:
Dmitri Makovetskiy wrote: ... " i will go" corresponds in the second sentence. so how can i make the program look for corresponding words, and identify them? ...

If you're looking for corresponding words, then I would not bother with individual chars. I would probably use String's split method to break the input into words, then write a method to compare sequences of these words using String's equals (or equalsIgnoreCase) method. Do not use ==.



the problem comes when the user might write a sentence with 100 ways. i cant compare all his words using loops or for methods.


i thought to make two variables

string end= " "

String Word= end+Str.charAt() + end

but how can i number each variable and make it look at the second string with no problem




i also came up with this one. but it tells me that St3, failed to initialize. how do i fix it and why is it caused?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Dmitri Makovetskiy wrote:...the problem comes when the user might write a sentence with 100 ways. i cant compare all his words using loops or for methods...

I think you can. But you need to be very careful about defining your algorithm -- the logical process you will use. Try writing this out step by step in Engligh before trying to code it.
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
but if " " character, i cant tell java to stop counting words before that space, can i ?


is there a way i could make java count all characters till " ", and then add all that character string to a variable called Word. then make java pass onto another String (after " ") find its characters till it reaches " ",
and add it to a word?
another variable
Words=Word+Words


is this direction possible? can it be done?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i break the String to bits?