Counting Special Characters

Type conversion can help you count special characters in a text. For example, if you'd like to find out the number of tab characters in a text, you should do this:

@([Byte[]][char[]]$text -eq 9).Count

This line will convert the characters in $text into bytes and uses -eq to filter only the character code for tabs (which is the number 9). Next, @() ensures that the result is an array so that you can use Count to check the number of found characters.

Twitter This Tip! ReTweet this Tip!


Posted Sep 10 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.