Using a regular expression you can count the number of lines as
str.split(/\r\n|\r|\n/).length
Alternately you can try split method as below.
var lines = $("#ptest").val().split("\n");
alert(lines.length);
working solution: http://jsfiddle.net/C8CaX/
More Related Contents:
- Is there a built in way to convert a comma-separated string to an array?
- Split large string in n-size chunks in JavaScript
- How can I convert a comma-separated string to an array?
- How can I split a string into segments of n characters?
- Split a string based on multiple delimiters
- String split returns an array with more elements than expected (empty elements)
- Unicode string with diacritics split by chars
- Javascript Array – Split string at numbers [closed]
- Count the recurrence of a word
- How to get character array from a string?
- Check if a JavaScript string is a URL
- How to check if a string contains text from an array of substrings in JavaScript?
- How to convert a string to an integer in JavaScript?
- How to set object property (of object property of..) given its string name in JavaScript?
- Shorten string without cutting words in JavaScript
- How can I insert a character after every n characters in javascript?
- How can I remove a character from a string using JavaScript?
- Javascript – return string between square brackets
- Case insensitive string replacement in JavaScript?
- JavaScript string with new line – but not using \n
- is the + operator less performant than StringBuffer.append()
- How to extract base URL from a string in JavaScript?
- Get the string representation of a DOM node
- Convert javascript array to string
- Need a basename function in Javascript
- Get object property name as a string
- Compare Strings Javascript Return %of Likely
- Split by Caps in Javascript
- how to split a string in javascript [duplicate]
- Does jQuery strip some html elements from a string when using .html()?