Remove tab ('\t') from string javascript -
Remove tab ('\t') from string javascript -
how can remove tab string on javascript?
when string comes buffer this:
<buffer 0d 0a 3c 25 72 65 73 70 6f 6e 73 65 2e 73 74 61 74 75 73 20...> function translate(data) { var content = data.tostring().split('\r\n'); } and perform following...
for example, have these lines:
'\t\t var session = request.getsession();' '\t\t session["user"] = {};' and want be:
'var session = request.getsession();' 'session["user"] = {};' by way, when do:
content=string(content).replace('\t',''); this why need string(...) constructor.
if wont utilize it, sick object has no method replace.
assuming content string want parse parses letter meaning this:
'\t session' becomes this:
's','e','s','s','i','o','n' why?
thanks help!
the problem in how define content.
if content=='\t session',
`content=string(content).replace('\t','');` implies content==' session'.
on side-note, string(...) unnecessary.
`content=content.replace('\t','');` achieves same result.
edit:
string(array) not work expect.
you have either perform replace before split string or perform replace on every element of 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 replace('\t', '') replace first occurrence of \t. global replace, utilize regexp alex k. suggested:
var content = data.tostring().replace(/\t/g, '').split('\r\n'); javascript string parsing
Comments
Post a Comment