1: $line=gc c:\Scripts\lettercase.txt
2: $arrLine=$line.ToCharArray()
3: foreach ($char in $arrLine) {
4: switch ([int]$char) {
5: {[int]$char -gt 100} {$letter=[int]$char - 32;$word+=[char]$letter}
6: {[int]$char -eq 32} {$word+=[char]$char}
7: {[int]$char -eq 33} {$word+=[char]$char}
8: {[int]$char -eq 51} {$letter=[int]$char - 1;$word+=[char]$letter}
9: {[int]$char -eq 49} {$letter=[int]$char - 1;$word+=[char]$letter}
10: {[int]$char -eq 57} {$letter=[int]$char - 1;$word+=[char]$letter}
11: default {$letter=[int]$char + 32;$word+=[char]$letter}
12: }
13: }
14: $word
Although not pretty at all it gets the job done. I simply cast the string into an array and convert each character to its lower or uppercase letter. For any numbers I subtracted one from the character value to get the correct number. Finally for any spaces and the exclamation point I do nothing and concatenate the value.
No comments:
Post a Comment