Thursday, December 6, 2012

Convert First letter a string to capital

Here is the function which is used to convert all the first letters of the name to capital Letters. 

 This idea of creating this  function is inspired with the words of my colleague   Kamal Relwani



function fnCapitalName(name){
    var a = name.trim().split(" ");
    var b = '';
    for(var i = 0;  i<a.length;i++){
         if(a[i] != ''){
             b += (a[i].substr(0,1).toUpperCase()+a[i].substr(1,a[i].length))+" ";
         }
    }
     return b;
}


Example: fnCapitalName("testing     name");



OutPut : Testing Name