look at the -replace operator
It will replace a RegEx with another string
$string -replace "ThisRegEx","WithThisOne"
Brandon Shell
---------------
Blog:
http://www.bsonposh.com/
PSH Scripts Project:
www.codeplex.com/psobject
J> I created a powershell script to create directories and rename files
J> based on MP3 tags..
J>
J> MP3 tags occasionally have characters the can't be used in
J> filenames/folders..
J>
J> My solution looks a bit ugly.. Is there a more efficient way to
J> replace all the special characters in a string than this?
J>
J> ---------------------------------------------------------------------
J> ------------
J>
J> ((((((((((" " + $media.Tag.Album).Trim()).Replace( ":" , " "
J> )).Replace("?" , " ")).Replace("/" , " ")).Replace("\" , "
J> ")).Replace("|" ," ")).Replace("*" , " ")).Replace("<" , "
J> ")).Replace(">" , " ")).Replace('"' , "")
J>
J> ---------------------------------------------------------------------
J> ------------
J>
J> Note: $media.Tag.Album would return a string like "Is there A
J> Key?/Are you there?".
J>
J> Creating a folder or file with that name would fail..
J>
J> My solution does remove all the special characters in a string. A
J> couple of the characters are replaced with nothing rather than a
J> space which was intentional.
J>
J> Any suggestions?
J>
J> Thanks
J>