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 how to compare characters between two strings? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to compare characters between two strings?" Watch "how to compare characters between two strings?" New topic
Author

how to compare characters between two strings?

rahul S Sharma
Greenhorn

Joined: Jun 08, 2011
Posts: 21
Hi everyone,
I am a beginner in java. My question is suppose two strings s1 and s2 are given.
String s1="bcd";
String s2="abc bcd def efg";
and its output should be aefg....
So please tell me how can i achieve this output...
thanks in advance...
Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 117
You can use toCharArray() and conatins() method's of String class and achieve your goal.
Check their usage in Java docs.


Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

hello ranch
As siddhesh said
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Should work.

Or in Scala
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

awesome logic man Luigi Plinge
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
vinayak jog wrote:awesome logic man Luigi Plinge . . .
But you have both done nothing to help rahul S Sharma. Rather you have deprived him of the opportunity of learning how to do it for himself, and maybe done more harm than good
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11313
    
  16

I will continue to delete any code provided that simply gives the answer to a homework problem.

Please resist the temptation to GIVE the answer out. We are here to TEACH people how to get the answer themselves.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
fred rosenberger wrote:I will continue to delete any code provided that simply gives the answer to a homework problem.

Please resist the temptation to GIVE the answer out. We are here to TEACH people how to get the answer themselves.
I left the code myslef because I thought it was too late to delete it.
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
I haven't seen what other people have suggested thus what I suggest may be same. If it is then please ignore my post.
One approach could be by taking s1 and removing occurrence of all s1’s characters from s2. Thus what you get after this removal would be the output you are looking for.
 
Consider Paul's rocket mass heater.
 
subject: how to compare characters between two strings?