![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
After getting some help working through my bugs, I have what seems to be a robust, working word counter script. I post it here to benefit others that might want this in the future and so that if I ever lose my copy I can come back here to find it Some other scripts that Iused for inspiration failed when confronted with whitespace before the string or miscalculated when encountering linefeeds and other non-space spaces, so I made mine better. Definition of words for this exercise is contiguous groups of characters separated by whitespace. Maybe it will even be useful to somebody besides me. Cheers! --David function trim(data) { while (/\s/.test(data.charAt(0))) {data=data.substring(1,data.length);} while (/\s/.test(data.charAt(data.length-1))) {data=data.substring(0,(data.length-1));} return data; } |
|
function countWords() { var input, wordList, output; input=document.forms[0].elements[0].value; input=trim(input); |
|
Grant Wagner <gwagner (AT) agricoreunited (DOT) com |
![]() |
| Thread Tools | |
| Display Modes | |
| |