Remove xA0 from powershell string -


i see few articles on removing xa0 character string in python, i'm not unfamiliar with, tips there not seem work powershell.

my problem i'm parsing excel file did 'ctrl+space' , created xa0 invisible character. i've removed excel sheet, i'm interested in knowing how filter/remove out these characters in general.

it causes problems when exporting these strings xml (doesn't characters).

if non-breaking space, can use -replace operator replace it:

ps c:\> $s = [string]::join([char]0x00a0, ('hello','world')) ps c:\> $s hello world ps c:\> $s -replace [char]0x00a0,'-' hello-world 

you might want replacement after creating xml:

ps c:\> ([psobject]@{"name"=$s} | convertto-xml -as string) -replace [char]0xa0,'&#160;' <?xml version="1.0"?> <objects>   <object type="system.collections.hashtable">     <property name="key" type="system.string">name</property>     <property name="value" type="system.string">hello&#160;world</property>   </object> </objects> 

or more complex replacement handle non-ascii characters:

ps c:\> $s = [string]::join([char]160, ("hello","powershell","world", "♥♥♥")) ps c:\> $myxml = $s | convertto-xml -as string ps c:\> ([regex]"[\u0080-\uffff]").replace($myxml, { param($m) "&#$([int][char]$m.value);" }) <?xml version="1.0"?> <objects>   <object type="system.string">hello&#160;powershell&#160;world&#160;&#9829;&#9829;&#9829;</object> </objects> ps c:\> 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -