比较Java中的两个段落更改

比较Java中的两个段落更改,java,regex,string,comparison,google-diff-match-patch,Java,Regex,String,Comparison,Google Diff Match Patch,我正在开发一个JavaWebApp,用户可以在其中更改文本区域。在这方面,他可以写一段,一句话。所以我现在要做的是用一个点分隔符把整个段落分开。完成后,我想检查一下哪些句子变了。 我目前正在使用for循环,这是不准确的,因为我必须将数组的长度转换为Math.minimum两个字符串数组的长度。但它不工作,我得到零字符串修改它。请让我知道我做错了什么 代码: String oldText = ""; String newText = ""; if(!(oldNotes.getNotete

我正在开发一个JavaWebApp,用户可以在其中更改文本区域。在这方面,他可以写一段,一句话。所以我现在要做的是用一个点分隔符把整个段落分开。完成后,我想检查一下哪些句子变了。 我目前正在使用for循环,这是不准确的,因为我必须将数组的长度转换为Math.minimum两个字符串数组的长度。但它不工作,我得到零字符串修改它。请让我知道我做错了什么

代码:

 String oldText = "";
 String newText = "";

  if(!(oldNotes.getNotetext().equals(newNotes.getNotetext()))){
            String[] strings = newNotes.getNotetext().split(".");
            if(strings.length>0){
                String[] oldNotesArray = oldNotes.getNotetext().split(".");
                if(oldNotesArray.length>0){
                    for(int i=0; i<Math.min(strings.length,oldNotesArray.length);i++){
                        if(!(strings[i].contains(oldNotesArray[i]))){
                            oldText += oldNotesArray[i];
                            newText += strings[i];
                        }
                    }
               }
                noteHistory.setNewText(newText);
                noteHistory.setHistoryText(oldText);
            } else {

                noteHistory.setNewText(newNotes.getNotetext());
                noteHistory.setHistoryText(oldNotes.getNotetext());
            }
        }
String oldText=”“;
字符串newText=“”;
如果(!(oldNotes.getNotetext().equals(newNotes.getNotetext())){
String[]strings=newNotes.getNotetext().split(“.”);
如果(字符串长度>0){
字符串[]oldNotesArray=oldNotes.getNotetext().split(“.”);
如果(oldNotesArray.length>0){

对于(int i=0;i使用
split(\\”)
获取按字符串拆分的字符串的精确数组,然后使用comapre还具有look

.split(.)分裂采用正则表达式和<代码>。在正则表达式中是特殊的。你需要逃离它。谢谢链接。你有什么例子我可以在这个上下文中使用它。非常感谢。@ WeaBrg,我没有任何例子,但是你可以很容易地把它谷歌,你可以得到它。如果它帮了你一些什么!!!
 diff_match_patch diffMatchPatch = new diff_match_patch();
                LinkedList<diff_match_patch.Diff> deltas = diffMatchPatch.diff_main(oldText,newText);
                for(diff_match_patch.Diff d : deltas){
                    if(d.operation== diff_match_patch.Operation.DELETE)
                        oldText += d.text;
                    else if(d.operation== diff_match_patch.Operation.INSERT)
                        newText += d.text;
                    else
                    {
                        oldText += d.text;
                        newText += d.text;
                    }
                }

                System.out.println(oldText);
                System.out.println(newText);