+ 3
Compare 2 Strings
I know how to compare 2 Strings, but I want to write out to the console parts of Strings that are same for both. Example: String text1 = "random"; String text2 = "tworanthing"; So here "ran" is same for both Strings. I want to know how to output it.
7 Réponses
+ 7
A way is to use two loops, an outer loop and inner loop.
The outer loop loops through all possible substrings of the first string and the inner will loop through all substrings of the second string(with length equal to the length of the current substring of the first string) to find all possible "equal" substrings
+ 6
What attempt have you made to do this?
+ 6
@RandomCoder
https://code.sololearn.com/ceM3Ehhm06qf/?ref=app
+ 5
@RandomCoder if you need further help, drop a comment on my code as I may miss a notification from here
+ 2
Thanks, I got it. I will give it a try :)
+ 1
I did not make it out because I don't know how to do it :P I tried to compare two Strings but it returns true or false so it is useless. I want to write same parts of those strings and not just return true of false
+ 1
String text1 = "aabbccdd";
String text2 = "eehhkkcc";
So same here is "cc" and I want to write it