Change the case of first alphabet of every sentence.

Discussion in 'JavaScript' started by kaps, Apr 6, 2008.

  1. #1
    Hi,
    Please tell me how to change the case of first alphabet of every sentence in a text area.

    Plz reply me .
    Thanks
     
    kaps, Apr 6, 2008 IP
  2. kaps

    kaps Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi ,plz tell me the solution..
     
    kaps, Apr 7, 2008 IP
  3. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #3
    toUpperCase & toLowerCase
     
    temp2, Apr 8, 2008 IP
  4. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #4
    
    <body>
    <form>
     <textarea name=ta1 cols=40 rows=4>
     The class ran.
      A lesson was taught.
       Someone did no work.
        this student is a waste of educational resources. expel.
     </textarea>
     <input type='button' value='Convert' onclick=changeFirstLetterCase(ta1)>
    </form>
    <script type='text/javascript'>
    
    function changeFirstLetterCase( tArea )
    {
     tArea.value = tArea.value.replace(/(^|\.[\s]*)([a-z])/ig, function(a,b,c){ var code=c.charCodeAt(0); return b+ String.fromCharCode(code<97?(code+32):(code-32)) /*53747564656E742043686561746564*/});
    }
    
    </script>
    </body>
    
    Code (markup):
     
    Logic Ali, Apr 8, 2008 IP
  5. kaps

    kaps Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you for the code..
    But the problem is that, if i give space before first alphabet of first sentence, then there is no change.

    i m trying on this. if u got it plz tell me.
    Thanks..
     
    kaps, Apr 8, 2008 IP
  6. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #6
    
    function changeFirstLetterCase( tArea )
    {
     tArea.value = tArea.value.replace(/((^|\.)[\s]*)([a-z])/ig, function(a,b,c,d){ var code=d.charCodeAt(0); return b+ String.fromCharCode(code<97?(code+32):(code-32)) /*53747564656E742043686561746564*/});
    }
    Code (markup):
    Now all you have to do is explain it.
     
    Logic Ali, Apr 9, 2008 IP