toupper and tolower
toupper turns every letter into a capital and tolower turns them into small letters, like a volume knob for text. It helps when you want words to look the same.
In this page:
Syntax
toupper(string)
tolower(string)
toupper and tolower
toupper() converts a string to all uppercase, and tolower() converts it to all lowercase. Both work element-wise across a vector of strings. They're commonly used for case-insensitive comparisons by normalizing both sides to the same case first.
Note:
For case-insensitive comparisons, normalize both strings with tolower() before comparing them with ==.
Example: toupper and tolower
text <- "Hello World"
cat(toupper(text), "\n")
cat(tolower(text), "\n")
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Expecting
toupper(text)to changetext, when it returns a new string unless you assign it. - Comparing strings without matching case, such as
"Yes" == "yes", which isFALSE; convert withtolower()first. - Using
toupperon a number and getting a string, when the value becomes character.
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: