Knowee
Questions
Features
Study Tools

How can you convert a lowercase character to uppercase manually in a string?

Question

How can you convert a lowercase character to uppercase manually in a string?

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step-by-step guide on how to convert a lowercase character to uppercase manually in a string:

  1. First, you need to identify the lowercase character that you want to convert to uppercase.

  2. Once you have identified the character, you need to find its ASCII value. ASCII value of a character can be found using the ord() function in Python. For example, the ASCII value of 'a' is 97.

  3. The ASCII values of lowercase letters are from 97 to 122 and for uppercase letters, they are from 65 to 90. So, to convert a lowercase letter to uppercase, you need to subtract 32 from its ASCII value.

  4. After subtracting 32 from the ASCII value of the lowercase letter, you need to convert this new ASCII value back to a character. This can be done using the chr() function in Python.

  5. Finally, replace the original lowercase character in the string with the new uppercase character.

Here is a Python code snippet that demonstrates this:

def convert_to_uppercase(s):
    new_string = ""
    for char in s:
        if 'a' <= char <= 'z':  # check if character is lowercase
            new_string += chr(ord(char) - 32)  # convert to uppercase
        else:
            new_string += char  # if not lowercase, keep original character
    return new_string

print(convert_to_uppercase("hello"))

This will output: "HELLO"

This problem has been solved

Similar Questions

Write a program that converts strings of all uppercase characters into strings of all lowercase and viceversa

How to convert a string str to lowercase characters?Astr.lower()Bstr.toLower()Cstr.toLowerCase()

What is the correct way to convert a string to uppercase in Java?Question 1Answera.toUpper()b.toUpperCase()c.uppercase()d.convertToUpperCase()

Write a python program to convert all the letters in the string to uppercasestring = "Hello World"print(string.upper())string = "Hello World"print(string.title())string = "Hello World"print(string.capitalize())string = "Hello World"print(string.Upper())

Which method can be used to return a string in upper case letters?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.