terça-feira, 27 de julho de 2010

Função Propercase

function toProperCase(s){
var i;
var returnString = "";
var tmpS=s.value.toLowerCase();
var arrS= new Array();
var arrS2 = new Array();
//search each word in array arrS
arrS=tmpS.split(" ");
for (i = 0; i < arrS.length; i++){
var thisWord=arrS[i];
//Check to see if word contains a hyphen
if(thisWord.indexOf("-")!=-1){
arrS2 = thisWord.split("-");
for(var j=0; j < arrS2.length; j++){
var thisWord2=arrS2[j];
returnString = returnString + thisWord2.charAt(0).toUpperCase() + thisWord2.substring(1,thisWord2.length)+"-";
}
returnString = returnString.substring(0,returnString.length-1)+" ";
} else {
returnString = returnString + thisWord.charAt(0).toUpperCase() + thisWord.substring(1,thisWord.length)+" ";
}
}
returnString = returnString.substring(0,returnString.length-1);
s.value = returnString;
}

Nenhum comentário:

Postar um comentário