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
In this post I am sharing how we can display the number of Vowels and Consonants in the given string
- function VowelsandConsonants
- {
- [CmdletBinding()]
- param (
- [Parameter(Mandatory)]
- [string] $InputString
- )
- [string] $VowelString
- [string] $ConsonantsString
- $StringLength = @()
- $StringLength = $InputString.Length
- for($i=0;$i -lt $StringLength;$i++)
- {
- 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")
- {
- $VowelString = $VowelString + $InputString[$i]
- }
- else
- {
- $ConsonantsString = $ConsonantsString + $InputString[$i]
- }
- }
- Write-Host "`n Vowles are !" $VowelString -foregroundcolor "green"
- Write-Host "`n Vowles are !" $VowelString.Length -foregroundcolor "green"
- Write-Host "`n Consonants are !" $ConsonantsString -foregroundcolor "red"
- Write-Host "`n Consonants are !" $ConsonantsString.Length -foregroundcolor "red"
- }
- VowelsandConsonants
Here is the output when we execute the script
No comments:
Post a Comment