So we needed analyze a case-sensitive text. We decided to store hold each word in a hashtable. That is simple enough.
$wordHash = @{}
$text='The little fox, flew over the ice'
$cleantext = ($text -replace '[,.]','')
$words = $cleantext.Split()
ForEach ($word in $words) {$wordHash[$word]++}
$wordHash| Name | Value |
|---|---|
| The | 2 |
| ice | 1 |
| over | 1 |
| flew | 1 |
| little | 1 |
| fox | 1 |
But what the.. We needed it case-sensitive but the hashtable thought The and the was the same.. So what now. By using changing @{} to the full form New-Object System.Collections.Hashtable we switch it to the case-sensitive form. Lets try again.
$wordHash = New-Object System.Collections.Hashtable
$text='The little fox, flew over the ice'
$cleantext = ($text -replace '[,.]','')
$words = $cleantext.Split()
ForEach ($word in $words) {$wordHash[$word]++}
$wordHash| the | 1 |
|---|---|
| fox | 1 |
| ice | 1 |
| The | 1 |
| flew | 1 |
| little | 1 |
| over | 1 |