Related Articles

Related Articles

Convert vowels into upper case character in a given string
  • Last Updated : 02 Nov, 2020

Given string str, the task is to convert all the vowels present in the given string to uppercase characters in the given string.

Examples:

Input: str = “GeeksforGeeks”
Output: GEEksfOrGEEks
Explanation:
Vowels present in the given string are: {‘e’, ‘o’}
Replace ‘e’ to ‘E’ and ‘o’ to ‘O’.
Therefore, the required output is GEEksfOrGEEks.

Input: str = “eutopia”
Output: EUtOpIA

Approach: The idea is to iterate over the characters of the given string and check if the current character is a lowercase character and a vowel or not. If found to be true, convert the character to its uppercase. Follow the steps below to solve the problem:



  • Traverse the given string and check if str[i] is a lowercase vowel or not.
  • If found to be true, replace str[i] to (str[i] – ‘a’ + ‘A’).
  • Finally, after complete the traversal of the string, print the final string.

Below is the implementation of the approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to implment
// the above approach
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to convert vowels
// into uppercase
string conVowUpp(string& str)
{
    // Stores the length
    // of str
    int N = str.length();
 
    for (int i = 0; i < N; i++) {
        if (str[i] == 'a' || str[i] == 'e'
            || str[i] == 'i' || str[i] == 'o'
            || str[i] == 'u') {
            str[i] = str[i] - 'a' + 'A';
        }
    }
    return str;
}
 
// Driver Code
int main()
{
    string str = "eutopia";
    cout << conVowUpp(str);
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to implment
// the above approach
import java.util.*;
class GFG{
 
// Function to convert vowels
// into uppercase
static void conVowUpp(char[] str)
{
  // Stores the length
  // of str
  int N = str.length;
 
  for (int i = 0; i < N; i++)
  {
    if (str[i] == 'a' || str[i] == 'e' ||
        str[i] == 'i' || str[i] == 'o' ||
        str[i] == 'u')
    {
      char c = Character.toUpperCase(str[i]);
      str[i] = c;
    }
  }
  for(char c : str)
    System.out.print(c);
}
 
// Driver Code
public static void main(String[] args)
{
  String str = "eutopia";
  conVowUpp(str.toCharArray());
}
}
 
// This code is contributed by 29AjayKumar

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to implement
# the above approach
 
# Function to convert vowels
# into uppercase
def conVowUpp(str):
     
    # Stores the length
    # of str
    N = len(str)
     
    str1 =""
     
    for i in range(N):
        if (str[i] == 'a' or str[i] == 'e' or
            str[i] == 'i' or str[i] == 'o' or
            str[i] == 'u'):
            c = (str[i]).upper()
            str1 += c
        else:
            str1 += str[i]
 
    print(str1)
 
# Driver Code
if __name__ == '__main__':
     
    str = "eutopia"
     
    conVowUpp(str)
 
# This code is contributed by Amit Katiyar

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to implment
// the above approach
using System;
class GFG{
 
// Function to convert vowels
// into uppercase
static void conVowUpp(char[] str)
{
  // Stores the length
  // of str
  int N = str.Length;
 
  for (int i = 0; i < N; i++)
  {
    if (str[i] == 'a' || str[i] == 'e' ||
        str[i] == 'i' || str[i] == 'o' ||
        str[i] == 'u')
    {
      char c = char.ToUpperInvariant(str[i]);
      str[i] = c;
    }
  }
  foreach(char c in str)
    Console.Write(c);
}
 
// Driver Code
public static void Main(String[] args)
{
  String str = "eutopia";
  conVowUpp(str.ToCharArray());
}
}
 
// This code is contributed by shikhasingrajput

chevron_right


Output: 

EUtOpIA











 

Time Complexity: O(N)
Auxiliary Space: O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :