Count characters in Powershell

I'm starting to make some scripts in PowerShell but I have a problem.

I want to count the number of characters that someone introduce by keyboard. I'm trying this:

write-host $FC
$numcar = $FC.Count

But it always returns 1.

Can someone help me?

1 Answer

Change your code to the following:

$FC = Read-Host -Prompt "Please enter some characters"
$numcar = $FC.length

You need to use the Read-Host command in order to get input from the keyboard. So this code sets the $FC variable to the data inputted from Read-Host and then the variable $numcar is set to the amount of characters entered, or 'length'. You got this confused with 'Count'.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like