nodejs: string manipulation
Problem
I have the following node.js code:
conn.on("data",function(x){
var responseData=x;
//sys.puts(responseData);
sys.puts(responseData.length);
var f=50;
var N=responseData.length;
if(N>f){
var p=Math.floor(N/f);
var p_rem=N%f;
var hash="";
for(var i=0;i
But substr doesn't appear to work!
How can I get substrings of a String in node.js?
Many thanks in advance,
Problem courtesy of: Eamorr
Solution
The variable data is of type Buffer, you would have to create a string with the method toString and then, you will be able to do the substr. Something like that will work :
responseData.toString().substr(1)
For more info consult this link :
http://nodejs.org/docs/v0.4.10/api/buffers.html#buffer.toString
Solution courtesy of: fe_lix_
Discussion
View additional discussion.