I got 2 questions:
-
My function looks like that
function count() {
var value = ids.val();
return (value == '') ? 0 : value.replace(/\s,?|,$/g, '').split(/\r\n|\r|\n/).length;
}
What I wanna do is, to skip whitespaces and count all new lines
For ex:
85
96
75
<whitespace>
76
count() must return 4 not 5. How can I modify my function?
- How to convert line break seperated words/numbers to comma seperated content?
For ex:
85
96
75<whitespace>
<whitespace>
76
I want to trim all whitespaces and convert whole content into something like that 85,96,75,76. How can I do it ?
The easiest way would be
.filter($.trim).map($.trim), which first removes any whitespace entries, and then cleans the remaining entries by removing surrounding spaces: http://jsfiddle.net/BtLzf/1/..filter/.mapare ES5 which means you’ll need a shim for older browsers.