I'm parsing through some data using javascript and getting results l开发者_C百科ike that look like this:
" The big\n brown dog. "
Of course, in a browser, this wouldn't look so funky:
The big brown dog
But in a text editor, it would look like this:
The big brown dog
Any ideas on the cleanest way to parse this, so it looks like it is supposed to as plain text?:
The big brown dog
Thanks!
var string = " The big\n brown dog. ";
string = string.replace(/\s{2,}/g, " ");
This just matches all whitespace (when 2 or more whitespace characters are next to each other) and then replaces it with a single space.
Input (minus the quotes):
"The big\n brown dog. "
Output (minus the quotes):
"The big brown dog. "
精彩评论