Converting Special Characters, Part 1

by Jul 21, 2014

All PowerShell versions

Sometimes it becomes necessary to replace special characters with other characters. Here is a simple function that does the trick:

function ConvertTo-PrettyText($Text)
{
  $Text.Replace('ü','ue').Replace('ö','oe').Replace('ä', 'ae' ).Replace('Ü','Ue').Replace('Ö','Oe').Replace('Ä', 'Ae').Replace('ß', 'ss')
}

Simply add as many Replace() calls as you need to process the text. Note that Replace() is case-sensitive which is great: you can do case-correct replacements that way.

PS> ConvertTo-PrettyText -Text 'Mr. Össterßlim'
Mr. Oesstersslim 

Twitter This Tip! ReTweet this Tip!