This is a simple one, but comes in useful any time I need to deal with data from a remote source.  I’m not saying all data that I don’t produce myself is garbage, but I am winking enthusiastically while suggesting it.  The main culprits are whitespace and a couple of special characters.  Whitespace alone isn’t a problem, you can just $var.trim the variables as you pass them, or during data gathering.  The special characters also need to be done though which makes it a pain to do as you pass variables, so I decided to throw everything into a little function.

function PowerScrub {
 Param ([string]$unscrub)
 #### Clear the whitespace off the ends
 $unscrub = $unscrub.trim()
 #### grave accent (in there twice, as grave accent (`') is an escape character in PS)
 $unscrub = $unscrub -replace "``", "'"
 #### acute accent
 $unscrub = $unscrub -replace "´", "'"
 #### Soft hyphen (take my word for it, it's there)
 $unscrub = $unscrub -replace "­", "-"
 #### Question mark
 $unscrub = $unscrub -replace "\?", ""
 return $unscrub
}

You may notice that depending on your editor of choice, this function will wreck your code highlighting due to the horrific mess of apostrophes, quotes and accents, as you see above.  It is all legit syntax though.  Looking back, I probably shouldn’t have made this my first code post.

Also, the soft hyphen isn’t showing for whatever web-browser based reason, but it is there, you’ll see if you copy/paste it into your editor.  Which bring up the question:  How on earth do people use the wrong hyphen?  How do they even find it?  I guess life… finds a way.

 

Leave a Reply

Your email address will not be published. Required fields are marked *