Javascript is used to compare whether two strings separated by the specified separator are the same. JS delimiter

Source: Internet
Author: User

Javascript is used to compare whether two strings separated by the specified separator are the same. JS delimiter

Compares the elements in two 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; // "55, csdn" var df1 = result. diff1; // ["55"] var df2 = result. diff2; // ["csdn"] * // compare the elements in two strings (character 1, character 2, separator optional) function diff (str1, str2, separator) {// str1 = str1 | ""; str2 = str2 | ""; separator = separator | ","; // arr contains the ele element function hasElement (arr, ele) {// memory loop va R 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, var res = []; for (var i1 = 0; i1 <. 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 result 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 it as needed. I used to compare tables exported in two Oracle databases that have not been imported successfully.


How does one implement JAVA string segmentation with two delimiters?

S1.split (", | .");
Implemented using a regular expression... | Represents or ....
, |. Is separated by commas (,) and dots ....

In addition, \. is used to represent vertices... This is because vertices have special meanings in the regular expression .. Represents any character...

Hope to help you .... If you still have problems, HI me...

Js splits strings by Separator

Var arrys = stringObj. split (/\ s + /);

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.