• Post Reply Bookmark Topic Watch Topic
  • New Topic

Determining differences between two strings  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am new here to learn java. Here is the problem:

I need to determine differences between two strings and then need to create new two strings. Also, I must find these strings in a string complex. Finding is OK but, the other one... For example:
First string: ATTTGCAACCGGT
Second string: ATTTCAAACCGGT
The program finds there two RNA chains correctly. But, I also need to find two more variations that are synthesized from that two strings. For two strings they are:
Third string: ATTTCCAACCGGT
Fourth string: ATTTGAAACCGGT
So, the program must take substring from those two strings when their difference starts. And create a new RNA chain.

P.s: I cannot use array class for this project.
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What problem are you exactly facing and were are you stuck?
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Turner wrote:I need to determine differences between two strings and then need to create new two strings.

Only two? Then I think you'll need to explain exactly how those two are determined, particularly since neither of your input Strings appear to be sorted. For Strings of the size you've shown, there are literally thousands of ways that they could be "different".

One algorithm for finding "differences" is diff, which uses a stepping-stone approach to determine (usually) the minimal set of differences between one string/line/file and another; but it's quite involved, and I'm not at all sure it's what you want.

So perhaps you could explain the requirements a bit more fully.

Winston
 
Jay Turner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Jay Turner wrote:I need to determine differences between two strings and then need to create new two strings.

Only two? Then I think you'll need to explain exactly how those two are determined, particularly since neither of your input Strings appear to be sorted. For Strings of the size you've shown, there are literally thousands of ways that they could be "different".

One algorithm for finding "differences" is diff, which uses a stepping-stone approach to determine (usually) the minimal set of differences between one string/line/file and another; but it's quite involved, and I'm not at all sure it's what you want.

So perhaps you could explain the requirements a bit more fully.

Winston


It can be more than 2 strings. Actually, It will be able to be changed by user of program. I need to find letter differences and split this letters.
 
Jay Turner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Welcome to the Ranch
What problem are you exactly facing and were are you stuck?

I must find differences between two strings as letters and need to create variations with these differences. For example, I have two string and they have just one letter different from each other. This program will search these two strings in larger string group and also search 2 more options. These options; when difference appears the program will create two more string with this difference. Example:
First string: ATTTGCAACCGGT
Second string: ATTTCAAACCGGT
We have G and C letter different here. I need to create 2 more strings with these differences. Like: ATTTCCAACCGGT ATTTGAAACCGGT. The program must search these two strings too. But, they may be different. For example, user can can enter strings that have different letters are different.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well then the first step would be to identify at which character does the difference start.
For a given pair of strings, can you identify that?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Turner wrote:I must find differences between two strings as letters and need to create variations with these differences. For example, I have two string and they have just one letter different from each other. This program will search these two strings in larger string group and also search 2 more options. These options; when difference appears the program will create two more string with this difference. Example:
First string: ATTTGCAACCGGT
Second string: ATTTCAAACCGGT
We have G and C letter different here. I need to create 2 more strings with these differences. Like: ATTTCCAACCGGT ATTTGAAACCGGT. The program must search these two strings too. But, they may be different. For example, user can can enter strings that have different letters are different.

Jay,

You don't need to include all quotes when you post. Just include the relevant part(s). It keeps threads shorter. I removed the redundant stuff from your third post.

We have G and C letter different here.

Not true. In the example you show above, what you have specifically is that String #1 is String #2 with 'GC' instead of 'CA'.

So, is this what ALL your situations are going to be like? - ie, one string will have exactly one difference from the other? (and it's arguable whether the above actually qualifies as only "one difference") Because if not, you still have the possibility of there being MANY differences between strings.

And in that case, "I need to create 2 more strings with...differences like" isn't good enough. WHAT, precisely, determines which two strings you are going to output? You plainly understand the problem, but you're not explaining it well to us.

Winston
 
Jay Turner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for now, let's say we will have just one different letter. How can I detect this between two strings?
 
Ranch Hand
Posts: 133
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Turner wrote:

P.s: I cannot use array class for this project.


That should not be a problem, as the program would come in at a later stage, the problem statement and logic needs to be formed first.

Jay Turner wrote:
Just for now, let's say we will have just one different letter. How can I detect this between two strings?


Also, the lengths of both the strings are going to be the same?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Turner wrote:Just for now, let's say we will have just one different letter. How can I detect this between two strings?

If you can assume that, simply run through the two strings, matching them character for character until you find a mismatch. Then you'll have the letter that's different.

But I would've thought you could have worked that one out for yourself.

BTW, you can get a specific character in a String with the charAt(int) method.

Winston
 
Jay Turner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rohit chavan wrote:
Jay Turner wrote:

P.s: I cannot use array class for this project.


That should not be a problem, as the program would come in at a later stage, the problem statement and logic needs to be formed first.

Jay Turner wrote:
Just for now, let's say we will have just one different letter. How can I detect this between two strings?


Also, the lengths of both the strings are going to be the same?


Yes, their lengths will be the same.

Winston Gutkowski wrote:
Jay Turner wrote:Just for now, let's say we will have just one different letter. How can I detect this between two strings?

If you can assume that, simply run through the two strings, matching them character for character until you find a mismatch. Then you'll have the letter that's different.

But I would've thought you could have worked that one out for yourself.

BTW, you can get a specific character in a String with the charAt(int) method.

Winston


This exactly is what I want to do. But, the problem is I am not be able to compare strings and find a mismatch.
 
rohit chavan
Ranch Hand
Posts: 133
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you doing to find the mismatch?

What is your current approach?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!