How can I remove tab from a any string on javascript?
when I get my string it comes as a buffer like this:
The problem is probably in how you define content
.
If content=='\t session'
,
`content=String(content).replace('\t','');`
implies that content==' session'
.
On a side-note, the String(...)
is unnecessary.
`content=content.replace('\t','');`
achieves the same result.
Edit:
String(array)
does not work as you expect.
You have to either perform the replace before you split the string or perform the replace on every element of the array separately.
Instead of
var content = data.toString().split('\r\n');
content=String(content).replace('\t','');
try
var content = data.toString().replace('\t', '').split('\r\n');
Note that replace('\t', '')
will replace only the first occurrence of \t
. To do a global replace, use the RegExp Alex K. suggested:
var content = data.toString().replace(/\t/g, '').split('\r\n');