header image

Archive for December, 2018

Count the occurrence of given character in a string

Posted by: | December 6, 2018 Comments Off on Count the occurrence of given character in a string |

Last time I showed how to get the number of occurrences of each character in a string but how do you count the occurrence of given character in a string?   You use one of the fundamental concepts on which PowerShell is built – its composability. In other words PowerShell is composed of a lot […]

under: PowerShell

Count occurrence of characters in a string

Posted by: | December 5, 2018 Comments Off on Count occurrence of characters in a string |

How do you count occurrence of characters in a string?   Group-object is a ready made cmdlet to answer this question function measure-occurrence { [CmdletBinding()] param ( [string]$teststring ) $teststring.ToCharArray() | Group-Object -NoElement | Sort-Object -Property Count -Descending }   Split the string into a character array. Pipe into group-object using –NoElement to drop the […]

under: PowerShell

« Newer Posts

Categories