Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting First Charcter of String to Upper Case [duplicate]

I have JavaScript Array that store String variable in it. I have tried below code that help me to convert Javascript variable to uppercase letter,

<html>
<body>

    <p id="demo"></p>

    <button onclick="toUppar()">Click Here</button>

    <script>
    Array.prototype.myUcase=function()
    {
        for (i=0;i<this.length;i++)
          {
          this[i]=this[i].toUpperCase();
          }
    }

    function toUppar()
    {
        var numArray = ["one", "two", "three", "four"];
        numArray.myUcase();
        var x=document.getElementById("demo");
        x.innerHTML=numArray;
    }
    </script>

</body>
</html>

but i want to convert only first character of Javascript Variable to Upper case.

Desired output : One,Two,Three,Four

like image 524
Vijay Avatar asked Aug 31 '13 09:08

Vijay


People also ask

How do you make the first character upper case?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

What is string :: toUpperCase?

Java String toUpperCase() Method The toUpperCase() method converts a string to upper case letters. Note: The toLowerCase() method converts a string to lower case letters.

How do you make the first letter uppercase in C++?

string str = "something"; str[0] = toupper(str[0]); That's all you need to do.


1 Answers

If you need the upper case for presentation to your views, you can simply use css for do so!

div.capitalize:first-letter {
  text-transform: capitalize;
}

here is the complete fiddle example: http://jsfiddle.net/wV33P/1/

like image 150
cl0udw4lk3r Avatar answered Sep 20 '22 04:09

cl0udw4lk3r