JS comparison of the elements within 2 strings (character 1, character 2, delimiter optional)

Source: Internet
Author: User
Tags diff

Compare elements within 2 strings (character 1, character 2, delimiter optional)

Files: diff.js

Example usage/*var str1 = "Tie, Mao,"; var str2 = "Tie, Mao, csdn"; var result = diff (str1, str2, ', ');   Object var rs = "" + result; "Csdn" var df1 = result.diff1; ["]var" DF2 = result.diff2; ["Csdn"]*///comparison of elements within 2 strings (character 1, character 2, delimiter optional) function diff (str1, str2, separator) {//str1 = str1 | | ""; str2 = str2 | | ""; Separator = Separator | | ",";//arr has ele element function haselement (arr, ele) {//memory loop var hasItem1 = False;for (var i2=0; i2 < arr.length; i2++) {//var I tem2 = Arr[i2] | | ""; if (!item2) {continue;} if (ele = = item2) {hasItem1 = True;break;}} return hasItem1;}; function Inanotb (A, B) {//In a, not in b var res = [];for (var i1=0; i1 < a.length; i1++) {var item1 = A[i1] | | ""; if (!item1) {continue;} var hasItem1 = haselement (b, Item1), if (!hasitem1) {Res.push (item1);}} Return res;};/ /var List1 = Str1.split (","), var list2 = Str2.split (",");//var diff1 = INANOTB (List1, list2); var diff2 = Inanotb (List2, Li ST1);//Returns the result var = {Diff1:diff1,diff2:diff2,separator:separator,tostring:functiOn () {//var res = this["diff1"].slice (0), res = Res.concat (this["diff2"]),//return res.join (this["separator"]);}};/ /return result;};

Please use as needed, I used to compare the exported tables in 2 Oracle databases with those not imported successfully.

JS comparison of the elements within 2 strings (character 1, character 2, delimiter optional)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.