• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3305
  • Last Modified:

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
0
calzone
Asked:
calzone
  • 3
  • 3
  • 2
  • +2
1 Solution
 
j3oneCommented:
Microsoft word will change it all to lowercase, then you can go back through and hit the uppercase parts...
0
 
GwynforWebCommented:
I do not understand this question, could you give an example.
0
 
calzoneAuthor Commented:
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
BustaroomsCommented:
<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).toUpperCase() + words[i].substring(1,words[i].length) + ' ';

alert(newWord);
return newWord;

}
</script>
0
 
GwynforWebCommented:
this is shorter

<script language="Javascript">
function firstLetter_Upper(theWord){
 newWord=theWord.replace(/^(.)/,function (d){return d.toUpperCase()})
 return newWord;
}

alert(firstLetter_Upper('abc'))
</script>
0
 
GwynforWebCommented:
<script language="Javascript">
function firstLetter_Upper(theWord){
 theWord=' '+theWord
 newWord=theWord.replace(/ (.)/g,function (d){return d.toUpperCase()})
 return newWord.replace(/ /,'');
}

alert(firstLetter_Upper('abc def ghi'))
</script>
0
 
calzoneAuthor Commented:
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
0
 
devicCommented:
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].toLowerCase().replace(/^([ a-z])/g,function (d){return d.toUpperCase()})
       return strArr.join(" ");
}

alert(firstLetter_Upper('CONVERT THIS TEXT '))
</script>
0
 
BustaroomsCommented:
ahhhhh good point

<script language="Javascript">
function firstLetter_Upper(theWord){
   theWord = theWord.toLowerCase();
   var words = theWord.split(' ');
   var newWord='';
    for(i=0; i < words.length; i++)
        newWord += words[i].charAt(0).toUpperCase() + words[i].substring(1,words[i].length) + ' ';

alert(newWord);
return newWord;

}
</script>
0
 
calzoneAuthor Commented:
Works great.

Thanks for the help Bustarooms.

Cal
0
 
devicCommented:
and my? doesn't work?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now