Counting Special Characters

by Sep 10, 2010

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!