Hey people...I'm having a problem stripping all the quotes out of a string. I was having an issue with commas from an array of words, but someone helped me out using join().
But now my string won't strip all the quotes. I've tried:
If you would provide an example of what you have and what you want
it would be a lot easier to answer your questions...
Code:
<script type="text/javascript">
var str = '"Now" is the "best" time for "all" good \"men\" to "come" to the \'aid\' of their "country".';
alert(str);
tstr = str.replace(/"/g,'');
alert(tstr);
</script>
the join doesn't strip everything. It will leave quotes in the string. Essentially I'm creating a word cloud. I take a bunch of text pulled from anywhere, then put it in a string first than split it into an array to be sorted etc. Then I output the array to a string where I apply the CSS styling depending on it's frequency of use.
The problem is when people use quotes such as "high way" what my code is picking up despite join or anything else ... what gets displayed is: "high. And then somewhere else in the word cloud:way" It pulls all other punctuation just not quotes for some reason.
you seem to be asking the same question over and over. if you start with an array of strings, .join() will strip the quotes out automatically:
Code:
var arr=["hello", "there"]
var end=arr.join("")
alert(end)
maybe you could show a sample string that you start with, the array that you end up with and explain how you want the result to be?
Here is all of the code for that function:
Code:
function execute()
{
var s = document.getElementById("input").value;
var punct_less = s.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,"");
var finalString = punct_less.replace(/\s{2,}/g,"");
var split = new Array();
split = finalString.split(" ");
var change= unique(split);
change.sort();
//find frequency of words
var frequency = new Array();
var counts = new Array();
var largest = 0;
var smallest = 1;
for(var i=0; i<change.length; i++) {
var mullet=0;
change[i] = change[i].replace(/^\s+|\s+$/g," ") ;
change[i] = change[i].replace(/\s{,}/g," ");
for(var j=0; j<split.length; j++) {
if (change[i]==split[j]) {
mullet=mullet+1;
}
frequency[i] = mullet;
}
}
//do math!!
for(var d=0; d<frequency.length; d++){
largest=Math.max(largest,frequency[d]); //find largest
}
var diff = largest-smallest; //difference, smallest is always 1
var dist = diff/3; //distribution
var large = 1 + (dist*2);
var medium = 1 + dist;
var small = .5 + dist;
//write out words
var final = new Array(); //declare new array
var i , j, z;
z=0;
var size = 0;
for( i = 0; i < frequency.length; i++) {
z = frequency[i];
size = getTagClass(z, smallest, small, medium, large, largest);
final[i] = "<span id ="+size+">"+change[i]+"</span>";
}
finalstr = final.join(" ");
for(var i=0; i < finalstr.length; i++)
{
finalstr.replace(/[\.",-\/#!$%\^&\*;:{}=\-_`"~()]/g,"");
finalstr.replace(/^\s+|\s+$/g,"");
finalstr.replace(/["']{1}/g,"");
}
document.getElementById("display").innerHTML = "<p id = 'tags'>" + finalstr + "</p>";
}
Bookmarks