Solved

Convert All Upper case to mixed case......

Posted on 2004-04-23
11
3,122 Views
Last Modified: 2008-01-16
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
Comment
Question by:calzone
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 9

Expert Comment

by:j3one
ID: 10902979
Microsoft word will change it all to lowercase, then you can go back through and hit the uppercase parts...
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10903004
I do not understand this question, could you give an example.
0
 

Author Comment

by:calzone
ID: 10903094
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
 
LVL 10

Expert Comment

by:Bustarooms
ID: 10903193
<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
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10903267
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10903300
<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
 

Author Comment

by:calzone
ID: 10903499
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
 
LVL 25

Expert Comment

by:devic
ID: 10903510
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
 
LVL 10

Accepted Solution

by:
Bustarooms earned 125 total points
ID: 10903519
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
 

Author Comment

by:calzone
ID: 10903836
Works great.

Thanks for the help Bustarooms.

Cal
0
 
LVL 25

Expert Comment

by:devic
ID: 10903842
and my? doesn't work?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now