Posted on by Kalkicode
Code String

Remove vowels from a string

Here given code implementation process.

// Java program
// Remove vowels from a string
class MyString
{
	//Check that whether given character is vowel or not
	public boolean is_vowel(char data)
	{
		if (data == 'a' 
            || data == 'e' 
            || data == 'i' 
            || data == 'o' 
            || data == 'u')
		{
			return true;
		}
		return false;
	}
	public String remove_vowels(String text)
	{
		//Get the size 
		int size = text.length();
		if (size <= 0)
		{
			return text;
		}
		//use to store result
		String result = "";
		for (int i = 0; i < size; i++)
		{
			if (is_vowel(text.charAt(i)) == false)
			{
				//When character is not vowel
				result += text.charAt(i);
			}
		}
		return result;
	}
	public static void main(String[] args)
	{
		MyString obj = new MyString();
		String text = "This is very interesting logic to find solution";
		System.out.print("Before : " + text);
		text = obj.remove_vowels(text);
		System.out.print("\nAfter : " + text);
	}
}

Output

Before : This is very interesting logic to find solution
After : Ths s vry ntrstng lgc t fnd sltn
//Include header file
#include <iostream>
#include<string.h>
using namespace std;

// C++ program
// Remove vowels from a string
class MyString
{
	public:
		//Check that whether given character is vowel or not
		bool is_vowel(char data)
		{
			if (data == 'a' || data == 'e' || data == 'i' || data == 'o' || data == 'u')
			{
				return true;
			}
			return false;
		}
	string remove_vowels(string text)
	{
		//Get the size 
		int size = text.size();
		if (size <= 0)
		{
			return text;
		}
		//use to store result
		string result = "";
		for (int i = 0; i < size; i++)
		{
			if (this->is_vowel(text[i]) == false)
			{
				//When character is not vowel
				result += text[i];
			}
		}
		return result;
	}
};
int main()
{
	MyString obj = MyString();
	string text = "This is very interesting logic to find solution";
	cout << "Before : " << text;
	text = obj.remove_vowels(text);
	cout << "\nAfter : " << text;
	return 0;
}

Output

Before : This is very interesting logic to find solution
After : Ths s vry ntrstng lgc t fnd sltn
//Include namespace system
using System;

// C# program
// Remove vowels from a string
class MyString
{
	//Check that whether given character is vowel or not
	public Boolean is_vowel(char data)
	{
		if (data == 'a' || data == 'e' || data == 'i' || data == 'o' || data == 'u')
		{
			return true;
		}
		return false;
	}
	public String remove_vowels(String text)
	{
		//Get the size 
		int size = text.Length;
		if (size <= 0)
		{
			return text;
		}
		//use to store result
		String result = "";
		for (int i = 0; i < size; i++)
		{
			if (is_vowel(text[i]) == false)
			{
				//When character is not vowel
				result += text[i];
			}
		}
		return result;
	}
	public static void Main(String[] args)
	{
		MyString obj = new MyString();
		String text = "This is very interesting logic to find solution";
		Console.Write("Before : " + text);
		text = obj.remove_vowels(text);
		Console.Write("\nAfter : " + text);
	}
}

Output

Before : This is very interesting logic to find solution
After : Ths s vry ntrstng lgc t fnd sltn
<?php
// Php program
// Remove vowels from a string
class MyString
{
	//Check that whether given character is vowel or not
	public	function is_vowel($data)
	{
		if ($data == 'a' 
            || $data == 'e' 
            || $data == 'i' 
            || $data == 'o' 
            || $data == 'u')
		{
			return true;
		}
		return false;
	}
	public	function remove_vowels($text)
	{
		//Get the size 
		$size = strlen($text);
		if ($size <= 0)
		{
			return $text;
		}
		//use to store result
		$result = "";
		for ($i = 0; $i < $size; $i++)
		{
			if ($this->is_vowel($text[$i]) == false)
			{
				//When character is not vowel
				$result .= $text[$i];
			}
		}
		return $result;
	}
}

function main()
{
	$obj = new MyString();
	$text = "This is very interesting logic to find solution";
	echo "Before : ". $text;
	$text = $obj->remove_vowels($text);
	echo "\nAfter : ". $text;
}
main();

Output

Before : This is very interesting logic to find solution
After : Ths s vry ntrstng lgc t fnd sltn
// Node Js program
// Remove vowels from a string
class MyString
{
	//Check that whether given character is vowel or not
	is_vowel(data)
	{
		if (data == 'a' 
            || data == 'e' 
            || data == 'i' 
            || data == 'o' 
            || data == 'u')
		{
			return true;
		}
		return false;
	}
	remove_vowels(text)
	{
		//Get the size 
		var size = text.length;
		if (size <= 0)
		{
			return text;
		}
		//use to store result
		var result = "";
		for (var i = 0; i < size; i++)
		{
			if (this.is_vowel(text[i]) == false)
			{
				//When character is not vowel
				result += text[i];
			}
		}
		return result;
	}
}

function main()
{
	var obj = new MyString();
	var text = "This is very interesting logic to find solution";
	process.stdout.write("Before : " + text);
	text = obj.remove_vowels(text);
	process.stdout.write("\nAfter : " + text);
}
main();

Output

Before : This is very interesting logic to find solution
After : Ths s vry ntrstng lgc t fnd sltn
#  Python 3 program
#  Remove vowels from a string
class MyString :
	# Check that whether given character is vowel or not
	def is_vowel(self, data) :
		if (data == 'a'
			or data == 'e'
			or data == 'i'
			or data == 'o'
			or data == 'u') :
			return True
		
		return False
	
	def remove_vowels(self, text) :
		# Get the size 
		size = len(text)
		if (size <= 0) :
			return text
		
		# use to store result
		result = ""
		i = 0
		while (i < size) :
			if (self.is_vowel(text[i]) == False) :
				# When character is not vowel
				result += text[i]
			
			i += 1
		
		return result
	

def main() :
	obj = MyString()
	text = "This is very interesting logic to find solution"
	print("Before : ", text, end = "")
	text = obj.remove_vowels(text)
	print("\nAfter : ", text, end = "")

if __name__ == "__main__": main()

Output

Before :  This is very interesting logic to find solution
After :  Ths s vry ntrstng lgc t fnd sltn
#  Ruby program
#  Remove vowels from a string
class MyString

	# Check that whether given character is vowel or not
	def is_vowel(data)
	
		if (data == 'a' || 
            data == 'e' || 
            data == 'i' || 
            data == 'o' || 
            data == 'u')
		
			return true
		end
		return false
	end
	def remove_vowels(text)
	
		# Get the size 
		size = text.length()
		if (size <= 0)
		
			return text
		end
		# use to store result
		result = ""
		i = 0
		while (i < size)
		
			if (self.is_vowel(text[i]) == false)
			
				# When character is not vowel
				result += text[i]
			end
			i += 1
		end
		return result
	end
end
def main()

	obj = MyString.new()
	text = "This is very interesting logic to find solution"
	print("Before : ", text)
	text = obj.remove_vowels(text)
	print("\nAfter : ", text)
end
main()

Output

Before : This is very interesting logic to find solution
After : Ths s vry ntrstng lgc t fnd sltn
// Scala program
// Remove vowels from a string
class MyString
{
	//Check that whether given character is vowel or not
	def is_vowel(data: Char): Boolean = {
		if (data == 'a' 
             || data == 'e' 
             || data == 'i' 
             || data == 'o' 
             || data == 'u')
		{
			return true;
		}
		return false;
	}
	def remove_vowels(text: String): String = {
		//Get the size 
		var size: Int = text.length();
		if (size <= 0)
		{
			return text;
		}
		//use to store result
		var result: String = "";
		var i: Int = 0;
		while (i < size)
		{
			if (is_vowel(text(i)) == false)
			{
				//When character is not vowel
				result += text(i);
			}
			i += 1;
		}
		return result;
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyString = new MyString();
		var text: String = "This is very interesting logic to find solution";
		print("Before : " + text);
		text = obj.remove_vowels(text);
		print("\nAfter : " + text);
	}
}

Output

Before : This is very interesting logic to find solution
After : Ths s vry ntrstng lgc t fnd sltn
// Swift program
// Remove vowels from a string
class MyString
{
	//Check that whether given character is vowel or not
	func is_vowel(_ data: Character) -> Bool
	{
		if (data == "a" 
            || data == "e" 
            || data == "i" 
            || data == "o" 
            || data == "u")
		{
			return true;
		}
		return false;
	}
	func remove_vowels(_ data: String) -> String
	{
      	let text = Array(data);
		//Get the size 
		let size: Int = text.count;
		if (size <= 0)
		{
			return data;
		}
		//use to store result
		var result: String = "";
		var i: Int = 0;
		while (i < size)
		{
			if (self.is_vowel(text[i]) == false)
			{
				//When character is not vowel
				result += String(text[i]);
			}
			i += 1;
		}
		return result;
	}
}
func main()
{
	let obj: MyString = MyString();
	var text: String = "This is very interesting logic to find solution";
	print("Before : ", text, terminator: "");
	text = obj.remove_vowels(text);
	print("\nAfter : ", text, terminator: "");
}
main();

Output

Before :  This is very interesting logic to find solution
After :  Ths s vry ntrstng lgc t fnd sltn

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