2024-10-01 15:11:03 +02:00
|
|
|
|
<#
|
2024-04-17 16:48:46 +02:00
|
|
|
|
.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"
|
2024-10-01 13:37:53 +02:00
|
|
|
|
✅ 11 characters counted in 'Hello World'.
|
2024-04-17 16:48:46 +02:00
|
|
|
|
.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
|
2024-10-01 13:37:53 +02:00
|
|
|
|
"✅ $numChars characters counted in '$givenString'."
|
2024-04-17 16:48:46 +02:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|