Using PowerShell makes it easy to compute the length of a string. PowerShell is inherited from the Microsoft. NET framework, so in the. NET inside how to get to the length of the string, in the PowerShell can use the same method.
We know that in. NET, you can use the String.Length method to get the length of the string, let us see how the PowerShell in the gourd painting gourd.
Copy Code code as follows:
$string = "1234567";
Write-host $string. Length;
#输出为7
If you're as lazy as a little weave, you can even write this:
Copy Code code as follows:
PS > "1234567". Length
7
What, is it easy? To illustrate, in PowerShell, these properties and methods are not case-sensitive, so in the. NET the length property, you write length also does not have any relation.
Finally, the small series has to mention the string with Chinese. Maybe you heard somewhere. The length of an English character is 1, and the length of a Chinese character is 2. But the little part is going to say, here in PowerShell, all the strings, the lengths are 1, like:
Copy Code code as follows:
PS > "Hello". length
2
OK, so much for the length of the PowerShell calculation string that I hope it will help.