calzone
asked on
Convert All Upper case to mixed case......
Does anybody know how to convert a string that is all in uppercase to a mixed case string in javascript. I know how to do this in PHP but I need to do this with javascript. I can't seem to find anything to do this.
Thanks
Cal
Thanks
Cal
Microsoft word will change it all to lowercase, then you can go back through and hit the uppercase parts...
I do not understand this question, could you give an example.
ASKER
I want to do this with a javascript function or command on a web page. I have a variable on a web page that is all uppercase. And I want to convert it to have The first letter of a word uppercase and the remaining letters in the word lowercase.
CONVERT THIS TEXT
into
Convert This Text
CONVERT THIS TEXT
into
Convert This Text
<script language="Javascript">
function firstLetter_Upper(theWord) {
var words = theWord.split(' ');
var newWord='';
for(i=0; i < words.length; i++)
newWord += words[i].charAt(0).toUpper Case() + words[i].substring(1,words [i].length ) + ' ';
alert(newWord);
return newWord;
}
</script>
function firstLetter_Upper(theWord)
var words = theWord.split(' ');
var newWord='';
for(i=0; i < words.length; i++)
newWord += words[i].charAt(0).toUpper
alert(newWord);
return newWord;
}
</script>
this is shorter
<script language="Javascript">
function firstLetter_Upper(theWord) {
newWord=theWord.replace(/^ (.)/,funct ion (d){return d.toUpperCase()})
return newWord;
}
alert(firstLetter_Upper('a bc'))
</script>
<script language="Javascript">
function firstLetter_Upper(theWord)
newWord=theWord.replace(/^
return newWord;
}
alert(firstLetter_Upper('a
</script>
<script language="Javascript">
function firstLetter_Upper(theWord) {
theWord=' '+theWord
newWord=theWord.replace(/ (.)/g,function (d){return d.toUpperCase()})
return newWord.replace(/ /,'');
}
alert(firstLetter_Upper('a bc def ghi'))
</script>
function firstLetter_Upper(theWord)
theWord=' '+theWord
newWord=theWord.replace(/ (.)/g,function (d){return d.toUpperCase()})
return newWord.replace(/ /,'');
}
alert(firstLetter_Upper('a
</script>
ASKER
Both of these functions are working if you start from a word that is all lowercase. But if you start from a word that is all uppercase they do not work. I am starting with all uppercase and need to get first letter upper and remaining letters lower.
Thanks
Cal
Thanks
Cal
if i undestood good, this wants calzone
========================== ===
<script>
function firstLetter_Upper(str)
{
var strArr=str.split(" ");
for(var i=0;i<strArr.length;i++)
strArr[i]=strArr[i].toLowe rCase().re place(/^([ a-z])/g,function (d){return d.toUpperCase()})
return strArr.join(" ");
}
alert(firstLetter_Upper('C ONVERT THIS TEXT '))
</script>
==========================
<script>
function firstLetter_Upper(str)
{
var strArr=str.split(" ");
for(var i=0;i<strArr.length;i++)
strArr[i]=strArr[i].toLowe
return strArr.join(" ");
}
alert(firstLetter_Upper('C
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great.
Thanks for the help Bustarooms.
Cal
Thanks for the help Bustarooms.
Cal
and my? doesn't work?