PowerShell method to get string length _powershell

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.