You can change the capitalization, or case, of selected text in a document by clicking a single button on the Home tab called Change Case.
Change case
To change the case of selected text in a document, do the following:
-
Select the text for which you want to change the case.
-
Go to Home > Change case .
-
Do one of the following:
-
To capitalize the first letter of a sentence and leave all other letters as lowercase, click Sentence case.
-
To exclude capital letters from your text, click lowercase.
-
To capitalize all of the letters, click UPPERCASE.
-
To capitalize the first letter of each word and leave the other letters lowercase, click Capitalize Each Word.
-
To shift between two case views (for example, to shift between Capitalize Each Word and the opposite, cAPITALIZE eACH wORD), click tOGGLE cASE.
Tips:
-
To apply small capital (Small Caps) to your text, select the text, and then on the Home tab, in the Font group, click the arrow in the lower-right corner. In the Font dialog box, under Effects, select the Small Caps check box.
-
To undo the case change, press CTRL+ Z.
-
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.
-
See also
Insert a drop cap
Choose AutoCorrect options for capitalization
Change case
To change the case of selected text in a document, do the following:
-
Select the text for which you want to change the case.
-
Go to Home > Change case .
-
Do one of the following:
-
To capitalize the first letter of a sentence and leave all other letters as lowercase, click Sentence case.
-
To exclude capital letters from your text, click lowercase.
-
To capitalize all of the letters, click UPPERCASE.
-
To capitalize the first letter of each word and leave the other letters lowercase, click Capitalize Each Word.
-
To shift between two case views (for example, to shift between Capitalize Each Word and the opposite, cAPITALIZE eACH wORD), click tOGGLE cASE.
Tips:
-
To apply small capital (Small Caps) to your text, select the text, and then on the Format menu, select Font, and in the Font dialog box, under Effects, select the Small Caps box.
Small Caps shortcut key: ⌘ + SHIFT + K
-
To undo the case change, press ⌘ + Z .
-
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and then press fn+ SHIFT + F3 until the style you want is applied.
-
See also
Insert a drop cap
Choose AutoCorrect options for capitalization
PowerPoint for the web supports changing case. See the procedure below.
Word for the web doesn’t support changing case. Use the desktop application to open the document and change text case there, or else you can manually change the casing of text in Word for the web.
-
Select the text you want to change.
-
Go to Home > More Font Options > Change case.
-
Choose the case you want to use.
I am trying to capitalize the first letter of only the first word in a sentence.
This is the data in the tsx file { this.text({ id: downloadPriceHistory
, defaultMessage: ‘Download Price History’ }) }
the id shown above comes from the database where it could be send to the api in various forms.
I have tried to use this logic below:
export function titleCase(string) {
string = 'hello World';
const sentence = string.toLowerCase().split('');
for (let i = 0; i < sentence.length; i++) {
sentence[i] = sentence[i][0].toUpperCase() + sentence[i];
}
return sentence;
}
For example, for the input "Download Price History"
, the result should be "Download price history"
.
Unmitigated
67.6k7 gold badges56 silver badges75 bronze badges
asked Aug 20, 2020 at 18:31
2
You only need to capitalize the first letter and concatenate that to the rest of the string converted to lowercase.
function titleCase(string){
return string[0].toUpperCase() + string.slice(1).toLowerCase();
}
console.log(titleCase('Download Price History'));
This can also be accomplished with CSS by setting text-transform
to lowercase
for the entire element and using the ::first-letter
pseudo element to set the text-transform
to uppercase
.
.capitalize-first {
text-transform: lowercase;
}
.capitalize-first::first-letter {
text-transform: uppercase;
}
<p class="capitalize-first">Download Price History</p>
answered Aug 20, 2020 at 18:36
UnmitigatedUnmitigated
67.6k7 gold badges56 silver badges75 bronze badges
use ES6 template strings feature:
const titleCase = str => `${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`
answered Sep 10, 2021 at 18:44
1
Using CSS:
p {
text-transform: lowercase;
}
p::first-letter {
text-transform: uppercase;
}
Using JS:
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
answered Aug 20, 2020 at 18:36
ConstantinConstantin
3,4771 gold badge14 silver badges22 bronze badges
2
try — make the rest of the string in lowercase as well.
export function titleCase(string) {
return string[0].toUpperCase() + string.substr(1).toLowerCase()
}
answered Aug 20, 2020 at 18:35
ManasManas
8081 gold badge7 silver badges16 bronze badges
Why not just lowercase the entire string, and the uppercase just the first letter of the new string?
function titleCase(string) {
let sentence = string.toLowerCase();
let titleCaseSentence = sentence.charAt(0).toUpperCase() + sentence.substring(1, sentence.length);
return titleCaseSentence;
}
(Also, you’re erasing your parameter to the function with that first line)
string = 'hello World';
Dharman♦
29.9k22 gold badges82 silver badges132 bronze badges
answered Aug 20, 2020 at 18:41
My suggestion is you get the first element of string and put in uppercase and get the rest of string and apply lowercase function.
titleCase(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
answered Aug 20, 2020 at 18:43
1
If you want Regex, in one line:
str.replace(/^(w)(.+)/, (match, p1, p2) => p1.toUpperCase() + p2.toLowerCase())
Explanation
It divides the string in 2 groups, the 1st character (w)
and the remaining characters (.+)
, and upper case the 1st group and lower case the second.
let str = 'the quick brown FOX'
str = str.replace(/^(w)(.+)/, (match, p1, p2) => p1.toUpperCase() + p2.toLowerCase())
console.log(str)
answered May 5, 2021 at 12:03
Great answers were provided already, but I’m just adding a different method using replace in case anyone needs it.
export function titleCase(string) {
string = 'hello World';
const sentence = string.toLowerCase();
let normalCaseString = sentence.replace(sentence[0], sentence[0].toUpperCase();
}
return normalCaseString;
}
The way this works is we’re utilizing the replace()
string method to swap the first letter in the sentence
variable with an uppercased version of it. The replace method takes two parameters, the first is the section you want to replace, and the second is what you want to replace it with.
Syntax: replace(pattern, replacement)
According to MDN, pattern
Can be a string or an object with a
Symbol.replace
method — the typical example being a regular expression. Any value that doesn’t have theSymbol.replace
method will be coerced to a string.
answered Sep 7, 2022 at 2:41
AlvinAlvin
7303 silver badges9 bronze badges
Updated: 12/30/2021 by
In Microsoft Word, you can use the keyboard shortcut Shift+F3 to change selected text between uppercase, lowercase, and title case.
Selecting a case
- Highlight all the text you want to change. If you want to change the case for the whole document you can use the Ctrl+A keyboard shortcut to select everything.
- Hold down Shift and press F3.
- When you hold Shift and press F3, the text toggles from sentence case (first letter uppercase and the rest lowercase), to all uppercase (all capital letters), and then all lowercase.
Note
If you are using a laptop or an Apple Mac, the function keys may not be enabled without the use of the Fn key. You may need to hold Fn, in addition to Shift, when you press F3.
If you’re not able to get Shift+F3 to work in Microsoft Word 2007 or later, you can try the following option instead.
- In the menu bar, on the Home tab, click the Change Case icon, which has an uppercase ‘A’ and lowercase ‘a.’
- Select the appropriate option from the list of values. For example, if you want to change to all uppercase letters, select the UPPERCASE option. If you want to change to all lowercase letters, select the lowercase option.
Tip
Use our text tool to convert any text from uppercase to lowercase.
You can change the case of selected text in a document by clicking the Change Case button on the ribbon. For example, you can change the selected text from lowercase to UPPERCASE.
-
Select the text for which you want to change the case.
-
On the Home tab, click Change Case .
-
Choose an option from the menu:
-
To capitalize the first letter of a sentence and leave all other letters lowercase, click Sentence case.
-
To exclude capital letters from your text, click lowercase.
-
To capitalize all of the letters, click UPPERCASE.
-
To capitalize the first letter of each word and leave the other letters lowercase, click Capitalize Each Word.
-
To shift between two case views (for example, between Capitalize Each Word and the opposite, cAPITALIZE eACH wORD, click tOGGLE cASE.
Notes:
-
To undo the case change, press + Z .
-
To format text in all small capital letters: Select the text, and then press COMMAND + SHIFT + K.
-
-
Select the text for which you want to change the case.
-
On the Home tab, under Font group, click Change Case .
-
Choose an option from the pop-up menu:
-
To capitalize the first letter of a sentence and leave all other letters lowercase, click Sentence case.
-
To exclude capital letters from your text, click lowercase.
-
To capitalize all of the letters, click UPPERCASE.
-
To capitalize the first letter of each word and leave the other letters lowercase, click Title Case.
-
To shift between two case views (for example, between Capitalize Each Word and the opposite, cAPITALIZE eACH wORD, click tOGGLE cASE.
Notes:
-
To undo the case change, press + Z .
-
To change case by using a keyboard shortcut, select the text, and then press SHIFT + F3 until the style you want—title case, all caps, or lowercase—is selected.
-
See also
Align or justify text
Apply a drop cap
In this tutorial, we will write the logic in 3 different programming languages that will accept a string from the user and convert the first letter of each word to uppercase (Capital alphabet) and convert the rest of the letters of each word to lowercase (small letters).
Algorithm
The algorithm behind the program is quite straightforward. We will traverse through every character of the string and check for the following conditions.
- if we are on the first character, just convert it to uppercase.
-
Else if check if the character is an empty space, if yes uppercase the next character value, and skip the next character by incrementing the traversing
i
pointer. - Else, for the rest of the letters, just convert them into lowercase.
#include <stdio.h>
#include <string.h>
int main()
{
//Initializing variables.
char str[100];
int i,length = 0;
//Accepting inputs.
printf("Enter a Sentance:n");
gets(str);
//calculate the length of the string
length = strlen(str);
for(i=0;i<length;i++)
{ // capitalize the first most letter
if(i==0)
{
str[i]=toupper(str[i]);
}
//check if the chracter is an empty space
// capitalize the next chracter
else if(str[i]==' ')
{
str[i+1]=toupper(str[i+1]);
i+=1; // skip the next chracter
}
else
{
str[i]=tolower(str[i]); // lowercase reset of the chracters
}
}
//Printing the sentance after changes.
printf("Sentance after the Change: %s", str);
return 0;
}
Output
Enter a Sentance:
thiS IS a GAME oF fiRe
Sentance after the Change: This Is A Game Of Fire
2. C++ Program to convert the first letter of each word of a string to uppercase and other to lowercase
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
//Initializing variables.
char str[100];
int i,length = 0;
//Accepting inputs.
cout<<"Enter a Sentance:n";
gets(str);
//calculate the length of the string
length = strlen(str);
for(i=0;i<length;i++)
{ // capitalize the first most letter
if(i==0)
{
str[i]=toupper(str[i]);
}
//check if the chracter is an empty space
// capitalize the next chracter
else if(str[i]==' ')
{
str[i+1]=toupper(str[i+1]);
i+=1; // skip the next chracter
}
else
{
str[i]=tolower(str[i]); // lowercase reset of the chracters
}
}
//Printing the sentance after changes.
cout<<"Sentance after the Change: "<< str;
return 0;
}
Output
Enter a Sentance:
thiS IS a GAME oF fiRe
Sentance after the Change: This Is A Game Of Fire
3. Python Program to convert the first letter of each word of a string to uppercase and other to lowercase
string = input("Enter a Sentance:n")
new_string =""
for i in range(len(string)):
if i==0:
new_string+= string[i].upper()
elif string[i-1]==" ":
new_string+=string[i].upper()
else:
new_string+= string[i].lower()
print("Sentance after the Change: ",new_string)
Output
Enter a Sentance:
thiS IS a GAME oF fiRe
Sentance after the Change: This Is A Game Of Fire
Note:
«Python strings are immutable, once initialize, can not be changed using assignment operator, that’s why we have used an additional string to achieve our task».
Complexity Analysis
-
Time Complexity: O(N),
because we are traversing through every character of the string using a single for loop. -
Space Complexity: O(1)
for C, C++, and
O(N)
for Python. Because in C and C++ we are performing the in-place replacement of the characters, but in Python, we have used an extra string.
Conclusion
Now let’s wrap up our article on «Write
a Program
to convert the first letter of each word of a string to uppercase and other to lowercase». In this article, we learned how to convert the first letter of each word into uppercase and the rest of the letters into lowercase.
People are also reading:
-
WAP to print the truth table for XY+Z
-
WAP in C to calculate the factorial of a number
-
WAP in C++ & Python to Calculate Compound Interest
-
WAP to calculate the average marks of 5 subjects
-
WAP in C++ & Python to reverse a number
-
WAP in C to check whether the number is a Palindrome number or not
-
WAP in C++ and python to check whether the year is a leap year or not
-
WAP to swap two numbers
-
WAP in C++ and python to check whether the number is even or odd
-
WAP to Print the Following Pattern
- Remove From My Forums
-
Question
-
1. Almost every time I add a cross-reference I need to change it by clicking on edit / lowercase. How can I make lowercase the defult option? Or how can I make a macro to do that!
2. How can I insert only the reference number, ex: See figure 1 and 2. Using corss-reference it will be: See figure 1 and figure 2. To remove the text «figure» I found only one HARD way:
insert * Arabi into the code. Ex:
normal: { REF _Ref154458335 h }
only number: { REF _Ref154458335 * Arabic h }How can I macro that since I can not right click when recording a macro (Im noob with macros).
Answers
-
Hi Pedro,
That makes the code much more complex, because Word provides no direct way of determining whether the selection is in a field:
Sub MakeLowRef()
Application.ScreenUpdating = False
Dim StrExt As String, Rng As Range
With Selection
Set Rng = .Range
FoundField:
If .Fields.Count > 0 Then
With .Fields(1)
If .Type = wdFieldRef Then
If InStr(.Code.Text, «* lower») > 0 Then Exit Sub
If InStr(.Code.Text, «h») > 0 Then StrExt = » h»
.Code.Text = Split(.Code.Text, «h»)(0) & «* lower» & StrExt
End If
.Update
End With
Else
Call GetField
If .Fields.Count > 0 Then GoTo FoundField
End If
End With
Rng.Select
Set Rng = Nothing
Application.ScreenUpdating = True
End SubSub MakeNumRef()
Application.ScreenUpdating = False
Dim StrExt As String, Rng As Range
With Selection
Set Rng = .Range
FoundField:
If .Fields.Count > 0 Then
With .Fields(1)
If .Type = wdFieldRef Then
If InStr(.Code.Text, «#») > 0 Then Exit Sub
If InStr(.Code.Text, «h») > 0 Then StrExt = » h»
.Code.Text = Split(.Code.Text, «h»)(0) & «# 0» & StrExt
End If
.Update
End With
Else
Call GetField
If .Fields.Count > 0 Then GoTo FoundField
End If
End With
Application.ScreenUpdating = True
End SubPrivate Sub GetField()
Dim lPos As Long
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
With Selection
lPos = .Start
‘Use ToggleShowCodes to move the selection if we’re not already at the start of a field
.Fields.ToggleShowCodes
.Fields.ToggleShowCodes
‘Retry one character later, in case the selection was already at the start of the field
If lPos = .Start Then
.Start = .Start + 1
lPos = .Start
.Fields.ToggleShowCodes
.Fields.ToggleShowCodes
End If
‘If the selection has moved, we’re in a field
If lPos <> .Start Then
.Fields.ToggleShowCodes
‘Find the end of the field
.MoveEndUntil cset:=Chr(21), Count:=256
.Fields.ToggleShowCodes
End If
End With
End Sub
Cheers
Paul Edstein
[MS MVP — Word]-
Marked as answer by
Monday, July 4, 2011 1:17 AM
-
Marked as answer by