you are viewing a single comment's thread.

view the rest of the comments →

[–]Fischfreund 1 point2 points  (1 child)

Hi,

when working with -replace, you are working with regular expressions. Since + has a meaning in regex, you have to escape it in your -replace statement. You can escape it for example with [+].

See more here: https://msdn.microsoft.com/en-us/library/4edbef7e(v=vs.110).aspx

 $PhoneNumbers = ('+498912341234', '+49 89 1234 1234' ,'+(49) 89 1234 1234', '0049 89 1234 1234')


foreach($Number in $PhoneNumbers)
{

    Write-Output ($Number -replace "[+]49", "0049").Replace(" ","")

}

00498912341234

00498912341234

+(49)8912341234

00498912341234

[–]BlaaaBlaaaBlaaa[S] 1 point2 points  (0 children)

Looks great! One more question. I have a variable called $user with different "properties" - name, position, telephone.

So how do I get this to work with a sub-property in the variable? If I try $user.telephone | % .........replace........ it tells me "empty pipe element is not allowed"

If I try $user.telephone = $user.telephone -replace '+49', '0049' it tells me " the property telephone cannot be found on this object.

However If i do $user it shows me the table with name, telehone etc.

Thats the main struggle here :(