-1
必須將字符串作爲單個單詞,以及如何比較和提取字符串或字符串以顯示差異?如何解析和比較文本?
也許可能有不同的解決方案讓它工作吧。
代碼
package parsetest;
import java.util.StringTokenizer;
public class ParseTest {
String saR1 = "This is a test for checking the content and a test for compare it";
String saR2 = "This is a test to the content and a test to make a comparsion";
String sResult1 = "";
String sResult2 = "";
String differences = "";
public static void main(String[] args) {
new ParseTest().parseMethod();
}
private void parseMethod() {
System.out.println("This is stringR1 :" + saR1);
System.out.println("This is stringR2 :" + saR2);
StringTokenizer st1 = new StringTokenizer(saR1); // do I need a StringTokenizer ?
StringTokenizer st2 = new StringTokenizer(saR2);
if(!saR1.equals(saR2)) {
while(st1.hasMoreTokens()) { // like below
sResult1 = st1.nextToken();
System.out.println("This is Result1 :" + sResult1);
}
while(st2.hasMoreTokens()) { // checks if there are more strings
sResult2 = st2.nextToken(); /next string
System.out.println("This is Result2 :" + sResult2);
if(sResult1.equals(sResult2)) { // when the strings are equal
differences = sResult1.replace(sResult2, ""); // extract the differences ?
}
} System.out.println("This is the difference :" + differences);
}
}}
You're已經與'bw.readLine()'讀他們,可以用'平等copare他們'''''''和其他一些'字符串'方法,但是你不清楚你真的在爲我打開什麼。 – SomeJavaGuy
請把真實[mcve];包括您正在使用的確切輸入的描述;預期和實際行爲。 – GhostCat
是的,對不起,我太過分了。我如何顯示字符串之間的差異,我需要StringTokenizer嗎? –