www.webdeveloper.com
Results 1 to 4 of 4

Thread: replace characters by regExp

  1. #1
    Join Date
    Aug 2009
    Posts
    38

    replace characters by regExp

    How can I replace alla first letters in every word in a string with upper case.
    I found that the regExp /\b[a-zA-Z]/ is the right one for finding first letters in every word, but trying
    Code:
    var upperStr = str.replace(/\b[a-zA-Z]/g," $&").toUpperCase();
    didn't work.


    I found this working script (that changes for example borderWidth to border-width), but I can't get it work for my purpose:
    Code:
    var newString = oldString.replace(/[A-Z]/g,"-$&").toLowerCase();





    Some ideas?

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Like this?
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>untitled</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function cnvrt2Upper(str) {
            return str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
            function cnvrt() {
                return arguments[0].toUpperCase();
            }
        }
    
    </script>
    </head>
    <body>
    <form action="">
    <input type="text" onblur="this.value=cnvrt2Upper(this.value)">
    </form>
    </body>
    </html>

  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thx for reply.

  4. #4
    Join Date
    Aug 2009
    Posts
    38
    Could you modify your function so that the letters after quote or double quote don't get affected. Thx.

    Ex: I'm hear --> I'm Hear (not I'M Hear)
    Ex: this "one" --> This "one" (not This "One")

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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