truncate text with double quotes in javascript
<p>I am using the below snippet to truncate text and it is working fine, except in cases where the text contains double quotes.</p>

<pre><code>function truncateText(str, len) {
return (str.length &gt; len ? $.trim(str).substring(0, len).split(" ").slice(0,-1).join("") :str);   
}
</code></pre>

<p>for example: 
len = 10
str = "helllllllo worlllld" - working fine.</p>

<p>but in case like this:</p>

<p>len = 10
str = "hellllll"o worlllld" - not working as expected.</p>

<p>I have tried to do the followings with no success:</p>

<pre><code>str = str.replace('"', '\"');
 str = str.replace('"', '&amp;quot');
 str = str.replace('"', '\x22');
</code></pre>
