admin管理员组文章数量:1323023
I have a jQuery selector which gets the html
within a selector, like so:
$('.pp-product-description .noindent').html()
Here's an example of the output, I've verified that it's a string:
<li class="standardBulletText">600 fill power down adds warmth without weight</li>
\r\n\t\t\t\t\t\t \t
<li class="standardBulletText">Matte shell with DriOff™ finish for water-resistant protection</li>\
r\n\t\t\t\t\t\t \t
<li class="standardBulletText">Snap-off, adjustable hood with removable faux fur trim</li>
\r\n\t\t\t\t\t\t \t<li class="standardBulletText">Hidden zip/snap closure except for top and bottom snaps</li>
I'm trying to trim this down so that the \r
, \n
and \t
characters disappear. I'm currently using nodeJS
' validate
module which has a special sanitize(string).trim()
command which should trim away white space. From the docs:
var str = sanitize(' \t\r hello \n').trim(); //'hello'
This has worked for me in the past, but here it isn't. I've also tried javascript's built in trim()
method, as well as str.replace("\s+", "");
, none are working.
Any ideas on what I'm missing, or what I can do to get this working?
I have a jQuery selector which gets the html
within a selector, like so:
$('.pp-product-description .noindent').html()
Here's an example of the output, I've verified that it's a string:
<li class="standardBulletText">600 fill power down adds warmth without weight</li>
\r\n\t\t\t\t\t\t \t
<li class="standardBulletText">Matte shell with DriOff™ finish for water-resistant protection</li>\
r\n\t\t\t\t\t\t \t
<li class="standardBulletText">Snap-off, adjustable hood with removable faux fur trim</li>
\r\n\t\t\t\t\t\t \t<li class="standardBulletText">Hidden zip/snap closure except for top and bottom snaps</li>
I'm trying to trim this down so that the \r
, \n
and \t
characters disappear. I'm currently using nodeJS
' validate
module which has a special sanitize(string).trim()
command which should trim away white space. From the docs:
var str = sanitize(' \t\r hello \n').trim(); //'hello'
This has worked for me in the past, but here it isn't. I've also tried javascript's built in trim()
method, as well as str.replace("\s+", "");
, none are working.
Any ideas on what I'm missing, or what I can do to get this working?
Share Improve this question asked Aug 19, 2013 at 7:05 JVGJVG 21.2k48 gold badges140 silver badges215 bronze badges 3 |1 Answer
Reset to default 26http://jsfiddle.net/HkJbr/....
.replace(/[\n\t\r]/g,"")
本文标签: nodejsTrimming nst from javascript stringStack Overflow
版权声明:本文标题:node.js - Trimming n, s, t from javascript string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738507166a2090598.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
trim
won't do anything, and the regex you tried is a string not a regex, so that won't do anything either... – elclanrs Commented Aug 19, 2013 at 7:07.replace()
just returns a replaced string. You need to dostr = str.replace(...)
. – Teemu Commented Aug 19, 2013 at 7:28