I don't know C#, this is how you can do picture formatting in javascript:
format = "(###)###-####"
input = 1234567890
formatted = format.replace(/#/g, [].shift.bind(String(input).split("")))
// result: "(123)456-7890"
To handle strings shorter than a picture, try this slightly more verbose code:
chars = String(input).split("")
formatted = format.replace(/#/g, function() { return chars.shift() || "" })