Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

replace method is case sensitive

7,524 views
Skip to first unread message

Frank

unread,
Jul 16, 2008, 4:34:04 PM7/16/08
to
Hi,

Powershell appears to be non casesensitive but when using replace:

$test="abcd"
$test.replace("A","Z")

is case sensitive, why is that?

Thanks,


Leo Tohill

unread,
Jul 16, 2008, 4:43:02 PM7/16/08
to
That's because .Replace() is a case-sensitive method on the .NET string
class.

This can certainly trip one up. You have to be aware of whether you are
using Powershell operators like -eq, -contains, etc or .Net methods like
.Equals, .Replace, .Contains .

Kiron

unread,
Jul 16, 2008, 4:48:19 PM7/16/08
to
Use the -Replace operator instead. By default it is case insensitive:
 
$test -replace 'A','Z'
 
# you can explicitly define it as case insensitive by prepending an 'i'
$test -ireplace 'A','Z'
 
# you can explicitly define it as case sensitive by prepending an 'c'
$test -creplace 'A','Z'

--
Kiron
0 new messages