Okay so I just started taking a beginner Java class, I have previous experience
ID: 3638561 • Letter: O
Question
Okay so I just started taking a beginner Java class, I have previous experience with C/C++, and have done much manipulation with the String Class, but I needed someone to explain to me how the Pattern class works in Java. Because I need to build a program that takes two strings such as String1: "Colorless light green ideas sleep furiously" and String2: "Furious dark green ideas sleep colorlessly" and then checks the two strings and prints out the most common substring within them. Example, after the program executes the two strings will come up with, green ideas sleep. Now i was able to use the matches function from the string library, but i need to write the program so that it is more dynamic with any two arbitrary strings. Any ideas would be appreciated. I am not looking for a full on program, just some help with this, thanks in advance.PS the pattern class is what we are supposed to use, but i am not sure how it works.
Explanation / Answer
You're going to have to use regular expressions. Pattern p = Pattern.compile("RegExString"); See this to learn regular expressions, which you can use in almost any language: http://docs.oracle.com/javase/tutorial/essential/regex/ This for more on the pattern class: http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html Also, one of my old CSC classes has a powerpoint online for regex: http://www.cct.lsu.edu/~sbrandt/csc1351/
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.