The JS implementation is used to compare the two strings separated by the specified delimiter _javascript tips

Source: Internet
Author: User
Tags diff

Compares elements within 2 strings (character 1, character 2, separator optional)

File: Diff.js

Example Usage/* var str1 = "Tie, Mao, 55";
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, separator 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 item2 = 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, List1); 
			return results var result = {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 tables exported in 2 Oracle databases with those that were not successfully imported.

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.