JavaScript string Numeric reversal letter case Interchange

Source: Internet
Author: User

String abcd123abcd456 How to convert to abcd321abcd654//number to reverse lowercase to uppercase, uppercase to lowercase Array.prototype.reverse = function () {var tmp;        for (var i = 0, j = this.length-1; I < J; i++, j--) {tmp = this[i];        This[i] = This[j];    THIS[J] = tmp; } return this;};        function foo (s) {var code, a = [], b, last = 0;//0 1:alpha 2:num for (var i = 0; i < s.length; i++) {        Code = s.charcodeat (i); if ((<= code && code <= 97 + 26-1) | | (<= code && code <= 65 + 26-1))            {if (last!== 1) {b = [], B.push (code), A.push (b);            } else {A[a.length-1].push (code);        } last = 1;  } else if (<= code && code <= + 9) {if (last!== 2) {b = [], B.push (code),            A.push (b);            } else {A[a.length-1].push (code);        } last = 2;       } else {if (last!== 0) {         b = [], B.push (code), A.push (b);            } else {A[a.length-1].push (code);        } last = 0;        }} s = A.map (function (a) {var c = a[0];        if (<= c && C <= + 9) {return a.reverse (); } else if (<= C && C <= + 26-1) {return A.map (function (c) {return (c &am            P;= 0XDF);        }); } else if (<= C && C <= + 26-1) {return A.map (function (c) {return (c |=            0x20);        });    } return A;        }). map (function (a) {return A.map (function (c) {return String.fromCharCode (c);    }). Join (');    }). Join ('); return s;} var s = "abcd123abcd456"; Console.log (foo (s));

  

> Node Char.js
abcd321abcd654

JavaScript string Numeric reversal letter case Interchange

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.