mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-25 17:33:17 +01:00
Added count-characters.ps1
This commit is contained in:
parent
dddfe0eb80
commit
46c80fcd36
28
scripts/count-characters.ps1
Normal file
28
scripts/count-characters.ps1
Normal file
@ -0,0 +1,28 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Counts the number of characters
|
||||
.DESCRIPTION
|
||||
This PowerShell script counts the number of characters in the given string.
|
||||
.PARAMETER GivenString
|
||||
Specifies the given string.
|
||||
.EXAMPLE
|
||||
PS> ./count-characters.ps1 "Hello World"
|
||||
✔️ 11 characters counted in 'Hello World'.
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$givenString = "")
|
||||
|
||||
try {
|
||||
if ($givenString -eq "" ) { $givenString = Read-Host "Enter the string" }
|
||||
|
||||
[int64]$numChars = $givenString.Length
|
||||
"✔️ $numChars characters counted in '$givenString'."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user