SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Dropvowels

  1. #1
    SitePoint Member
    Join Date
    May 2004
    Location
    london
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Dropvowels

    Hello all,

    does anyone have a clue on how to drop vowels in javascript.

    That is removing all the upper a lower case vowels?

    any help would be great! JAZZ = JZZ

    jaz

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use a regular expression.

    Unfortunately they are not my strong point.

    Or, on a char by char basis just copy the string to a new string via an if which says if not A, E, I, O, U, a, e, i, o, u then copy

    you'd use for i=0, i<string.length,i++ as the loop control

    The rest is up to you.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>::: destroy all vowels :::</title>
    <script type="text/javascript">
    
    String.prototype.stripVowels = function(sReplacement, bIncludeY)
    {
    	var oRegExp = new RegExp('[aeiou' + ((bIncludeY) ? 'y' : '') + ']', 'gi');
    	return this.replace(oRegExp, sReplacement || '');
    }
    
    </script>
    </head>
    <body>
    <div id="readout" style="position:absolute;top:50px;left:120px;font-weight:bold;"></div>
    <button style="width:200px;margin:100px;" onclick="return demo()">go</button>
    <script type="text/javascript">
    
    function demo()
    {
    	var str = prompt('Enter a word or phrase. Kiss your vowels goodbye.', 'facetiously');
    	if (null != str)
    		document.getElementById('readout').innerHTML = 'before: ' + str + '<br />after: ' + str.stripVowels('', true);
    	return false;
    }
    
    </script>
    </body>
    </html>
    Could modify this easily.
    Last edited by adios; May 2, 2004 at 16:41.
    ::: certified wild guess :::

  4. #4
    SitePoint Member
    Join Date
    May 2004
    Location
    london
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    Dr John and Adios !


Bookmarks

Posting Permissions

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