Posted on by Kalkicode
Code String

Remove consecutive vowels from string

Here given code implementation process.

// Java program
// Remove consecutive vowels from string
class MyString
{
	public boolean is_vowel(String text, int location)
	{
		if (text.charAt(location) == 'a' || text.charAt(location) == 'e' || text.charAt(location) == 'i' || text.charAt(location) == 'o' || text.charAt(location) == 'u')
		{
			return true;
		}
		return false;
	}
	public String remove_consecutive_vowels(String text)
	{
		int size = text.length();
		if (size <= 0)
		{
			return text;
		}
		String result = "";
		result += text.charAt(0);
		for (int i = 1; i < size; i++)
		{
			if (!(is_vowel(text, i - 1) && is_vowel(text, i)))
			{
				//When no two consecutive vowels are not exist
				result += text.charAt(i);
			}
		}
		return result;
	}
	public static void main(String[] args)
	{
		MyString obj = new MyString();
		String text = "quick search your destination";
		System.out.print("Before : " + text);
		text = obj.remove_consecutive_vowels(text);
		System.out.print("\nAfter : " + text);
	}
}

Output

Before : quick search your destination
After : quck serch yor destinatin
//Include header file
#include <iostream>
#include<string.h>
using namespace std;

// C++ program
// Remove consecutive vowels from string
class MyString
{
	public: bool is_vowel(string text, int location)
	{
		if (text[location] == 'a' 
            || text[location] == 'e' 
            || text[location] == 'i' 
            || text[location] == 'o' 
            || text[location] == 'u')
		{
			return true;
		}
		return false;
	}
	string remove_consecutive_vowels(string text)
	{
		int size = text.size();
		if (size <= 0)
		{
			return text;
		}
		string result = "";
		result += text[0];
		for (int i = 1; i < size; i++)
		{
			if (!(this->is_vowel(text, i - 1) && this->is_vowel(text, i)))
			{
				//When no two consecutive vowels are not exist
				result += text[i];
			}
		}
		return result;
	}
};
int main()
{
	MyString obj = MyString();
	string text = "quick search your destination";
	cout << "Before : " << text;
	text = obj.remove_consecutive_vowels(text);
	cout << "\nAfter : " << text;
	return 0;
}

Output

Before : quick search your destination
After : quck serch yor destinatin
//Include namespace system
using System;
// C# program
// Remove consecutive vowels from string
class MyString
{
	public Boolean is_vowel(String text, int location)
	{
		if (text[location] == 'a' 
            || text[location] == 'e' 
            || text[location] == 'i' 
            || text[location] == 'o' 
            || text[location] == 'u')
		{
			return true;
		}
		return false;
	}
	public String remove_consecutive_vowels(String text)
	{
		int size = text.Length;
		if (size <= 0)
		{
			return text;
		}
		String result = "";
		result += text[0];
		for (int i = 1; i < size; i++)
		{
			if (!(is_vowel(text, i - 1) && is_vowel(text, i)))
			{
				//When no two consecutive vowels are not exist
				result += text[i];
			}
		}
		return result;
	}
	public static void Main(String[] args)
	{
		MyString obj = new MyString();
		String text = "quick search your destination";
		Console.Write("Before : " + text);
		text = obj.remove_consecutive_vowels(text);
		Console.Write("\nAfter : " + text);
	}
}

Output

Before : quick search your destination
After : quck serch yor destinatin
<?php
// Php program
// Remove consecutive vowels from string
class MyString
{
	public	function is_vowel($text, $location)
	{
		if ($text[$location] == 'a' 
            || $text[$location] == 'e' 
            || $text[$location] == 'i' 
            || $text[$location] == 'o' 
            || $text[$location] == 'u')
		{
			return true;
		}
		return false;
	}
	public	function remove_consecutive_vowels($text)
	{
		$size = strlen($text);
		if ($size <= 0)
		{
			return $text;
		}
		$result = "";
		$result .= $text[0];
		for ($i = 1; $i < $size; $i++)
		{
			if (!($this->is_vowel($text, $i - 1) && $this->is_vowel($text, $i)))
			{
				//When no two consecutive vowels are not exist
				$result .= $text[$i];
			}
		}
		return $result;
	}
}

function main()
{
	$obj = new MyString();
	$text = "quick search your destination";
	echo "Before : ". $text;
	$text = $obj->remove_consecutive_vowels($text);
	echo "\nAfter : ". $text;
}
main();

Output

Before : quick search your destination
After : quck serch yor destinatin
// Node Js program
// Remove consecutive vowels from string
class MyString
{
	is_vowel(text, location)
	{
		if (text[location] == 'a' 
            || text[location] == 'e' 
            || text[location] == 'i' 
            || text[location] == 'o' 
            || text[location] == 'u')
		{
			return true;
		}
		return false;
	}
	remove_consecutive_vowels(text)
	{
		var size = text.length;
		if (size <= 0)
		{
			return text;
		}
		var result = "";
		result += text[0];
		for (var i = 1; i < size; i++)
		{
			if (!(this.is_vowel(text, i - 1) && this.is_vowel(text, i)))
			{
				//When no two consecutive vowels are not exist
				result += text[i];
			}
		}
		return result;
	}
}

function main()
{
	var obj = new MyString();
	var text = "quick search your destination";
	process.stdout.write("Before : " + text);
	text = obj.remove_consecutive_vowels(text);
	process.stdout.write("\nAfter : " + text);
}
main();

Output

Before : quick search your destination
After : quck serch yor destinatin
#  Python 3 program
#  Remove consecutive vowels from string
class MyString :
	def is_vowel(self, text, location) :
		if (text[location] == 'a'
			or text[location] == 'e'
			or text[location] == 'i'
			or text[location] == 'o'
			or text[location] == 'u') :
			return True
		
		return False
	
	def remove_consecutive_vowels(self, text) :
		size = len(text)
		if (size <= 0) :
			return text
		
		result = ""
		result += text[0]
		i = 1
		while (i < size) :
			if (not (self.is_vowel(text, i - 1) and self.is_vowel(text, i))) :
				# When no two consecutive vowels are not exist
				result += text[i]
			
			i += 1
		
		return result
	

def main() :
	obj = MyString()
	text = "quick search your destination"
	print("Before : ", text, end = "")
	text = obj.remove_consecutive_vowels(text)
	print("\nAfter : ", text, end = "")

if __name__ == "__main__": main()

Output

Before :  quick search your destination
After :  quck serch yor destinatin
#  Ruby program
#  Remove consecutive vowels from string
class MyString

	def is_vowel(text, location)
	
		if (text[location] == 'a' || 
            text[location] == 'e' || 
            text[location] == 'i' || 
            text[location] == 'o' || 
            text[location] == 'u')
		
			return true
		end
		return false
	end
	def remove_consecutive_vowels(text)
	
		size = text.length()
		if (size <= 0)
		
			return text
		end
		result = ""
		result += text[0]
		i = 1
		while (i < size)
		
			if (!(self.is_vowel(text, i - 1) && self.is_vowel(text, i)))
			
				# When no two consecutive vowels are not exist
				result += text[i]
			end
			i += 1
		end
		return result
	end
end
def main()

	obj = MyString.new()
	text = "quick search your destination"
	print("Before : ", text)
	text = obj.remove_consecutive_vowels(text)
	print("\nAfter : ", text)
end
main()

Output

Before : quick search your destination
After : quck serch yor destinatin
// Scala program
// Remove consecutive vowels from string
class MyString
{
	def is_vowel(text: String, location: Int): Boolean = {
		if (text(location) == 'a' 
      || text(location) == 'e' 
      || text(location) == 'i' 
      || text(location) == 'o' 
      || text(location) == 'u')
		{
			return true;
		}
		return false;
	}
	def remove_consecutive_vowels(text: String): String = {
		var size: Int = text.length();
		if (size <= 0)
		{
			return text;
		}
		var result: String = "";
		result += text(0);
		var i: Int = 1;
		while (i < size)
		{
			if (!(is_vowel(text, i - 1) && is_vowel(text, i)))
			{
				//When no two consecutive vowels are not exist
				result += text(i);
			}
			i += 1;
		}
		return result;
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyString = new MyString();
		var text: String = "quick search your destination";
		print("Before : " + text);
		text = obj.remove_consecutive_vowels(text);
		print("\nAfter : " + text);
	}
}

Output

Before : quick search your destination
After : quck serch yor destinatin
// Swift program
// Remove consecutive vowels from string
class MyString
{
	func is_vowel(_ char_data: Character) -> Bool
	{
		if (char_data == "a" 
            || char_data == "e" 
            || char_data == "i" 
            || char_data == "o" 
            || char_data == "u")
		{
			return true;
		}
		return false;
	}
	func remove_consecutive_vowels(_ data: String) -> String
	{
		let size: Int = data.count;
      	let text = Array(data);
		if (size <= 0)
		{
			return data;
		}
		var result: String = "";
		result += String(text[0]);
		var i: Int = 1;
		while (i < size)
		{
			if (!(self.is_vowel(text[i - 1]) && self.is_vowel(text[i])))
			{
				//When no two consecutive vowels are not exist
				result += String(text[i]);
			}
			i += 1;
		}
		return result;
	}
}
func main()
{
	let obj: MyString = MyString();
	var text: String = "quick search your destination";
	print("Before : ", text, terminator: "");
	text = obj.remove_consecutive_vowels(text);
	print("\nAfter : ", text, terminator: "");
}
main();

Output

Before :  quick search your destination
After :  quck serch yor destinatin

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment