www.webdeveloper.com
Results 1 to 8 of 8

Thread: stripping ALL quotes""

  1. #1
    Join Date
    May 2012
    Posts
    8

    stripping ALL quotes""

    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:

    Code:
    finalstr.replace(/"/g, "");
    I've also tried:
    Code:
    finalstr.replace(/[\.,""-\/#!$%\^&\*;:{}=\-_`~()]/g,"");
    				finalstr.replace(/^\s+|\s+$/g," ") ;
    I know some of those reg exp are redundant but if I don't have them in...it doesn't strip everything. Any clues, hints or just generally criticism?

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    finalstr.replace(/^\s+|\s+$/g," "); what does this do?
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Nov 2010
    Posts
    1,081
    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?

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364

    Lightbulb

    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>
    Last edited by JMRKER; 05-19-2012 at 09:51 PM.

  5. #5
    Join Date
    May 2012
    Posts
    8
    Actually it's the same issue over and over again.

    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.

  6. #6
    Join Date
    May 2012
    Posts
    8
    Quote Originally Posted by xelawho View Post
    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>";
    				
    		}

  7. #7
    Join Date
    Nov 2010
    Posts
    1,081
    Uncaught ReferenceError: unique is not defined

  8. #8
    Join Date
    May 2012
    Posts
    8
    function unique(x) {
    tmp = new Array(0);
    for(i=0;i<x.length;i++) {
    if(!contains(tmp, x[i])) {
    tmp.length+=1;
    tmp[tmp.length-1]=x[i];
    }
    }
    return tmp;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles