how separator to string at every n charaters in javascript

In Js:

function valuechar(str, n) {
    var char = [], i, len;

    for(i = 0, len = str.length; i < len; i += n) {
       char.push(str.substr(i, n))
    }
    return char
};

valuechar("ABCUSERHERE",3).join('-');

In C#:

for (int i = 2; i < str.Length; i += 3)
        str= str.Insert(i, "-");

Post a Comment

0 Comments