Monday, July 18, 2016

Vowels and Consonants using power shell

I started working on power shell, I am doing some basic examples which I will share so that it might help some one

In this post I am sharing how we can display the number of Vowels and Consonants in the given string

  1. function VowelsandConsonants  
  2. {  
  3.     [CmdletBinding()]  
  4.     param (  
  5.         [Parameter(Mandatory)]  
  6.         [string] $InputString   
  7.     )  
  8.       
  9.     [string] $VowelString  
  10.     [string] $ConsonantsString  
  11.     $StringLength = @()  
  12.       
  13.     $StringLength = $InputString.Length  
  14.   
  15.     for($i=0;$i -lt $StringLength;$i++)  
  16.     {  
  17.       
  18.         if($InputString[$i] -eq "a" -or $InputString[$i] -eq "e" -or $InputString[$i] -eq "i" -or $InputString[$i] -eq "o" -or $InputString[$i] -eq "u")  
  19.         {  
  20.             $VowelString = $VowelString + $InputString[$i]  
  21.         }  
  22.         else  
  23.         {  
  24.             $ConsonantsString = $ConsonantsString + $InputString[$i]  
  25.         }  
  26.     }  
  27.       
  28.     Write-Host "`n Vowles are !" $VowelString -foregroundcolor "green"  
  29.     Write-Host "`n Vowles are !" $VowelString.Length -foregroundcolor "green"  
  30.     Write-Host "`n Consonants are !" $ConsonantsString -foregroundcolor "red"  
  31.     Write-Host "`n Consonants are !" $ConsonantsString.Length -foregroundcolor "red"  
  32. }  
  33.   
  34. VowelsandConsonants

Here is the output when we execute the script


No comments:

Post a Comment

Popular Posts