Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

JavaScript: Shift character values by 1 for every character

How can I increase the value of all characters by one value?  "A" should become "B" and "1" should become "2":

var x = '123abc';
alert( shift(x) ); // should alert('234bcd');

Open in new window

Avatar of clockwatcher
clockwatcher

Here's one way:
        var x = '123abc';
        alert(x.replace(/(.)/g, function (x,p1) { return String.fromCharCode(p1.charCodeAt(0)+1) }));

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial