I’ve got the following code in Node.js:
var str = '',
ch;
for(/*standard for loop*/){
// some code ...
ch = '%' + buffer[i].toString(16);
str += ch;
}
Now when buffer[i].toString(16) returns, let’s say d6, resulting string doesn’t contain %d6, but NaN6 instead.
Now I know %d is used in C’s sprinf, but afaik JavaScript nor Node has sprintf or equivalent function.
I need %d6 in my string, so what can I do to prevent JS from automatically converting %d (and others, like %f) to NaN?
Node’s console.log() – the standard function for outputting – that I was using to print out the result behaves as printf and that is actually documented (http://nodejs.org/docs/v0.4.11/api/stdio.html#console.log). Silly me, thanks averyone for leding me to the solution.
sys.puts() prints the expected string.