![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | $_.contains versus -contains $_.contains versus -contains... Should these behave differently? 175# $test=@" >> test 123 >> "@ >> 176# $test -contains 123 False 177# $test -contains "123" False 178# $test|foreach-object{$_.contains("123")} True 179# $test -contains "test 123" True (I seem to remember that I think it was also different behaviour between $_.replace and -replace.) Marco |
My System Specs![]() |
| | #2 (permalink) |
| | Re: $_.contains versus -contains I think $_.contains('x') is similar to $_ -match 'x' or $_ -like "*x*" $_ -contains 'x' checks 'x' against a collection of elements in $_ to match. "test 123".contains('1') "test 123" -match 1 "test 123", "456", 768 -contains 456 -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: $_.contains versus -contains "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message news:Or3eJcKwHHA.3508@TK2MSFTNGP03.phx.gbl... > $_.contains versus -contains... > > Should these behave differently? > > 175# $test=@" > >> test 123 > >> "@ > >> > 176# $test -contains 123 > False > 177# $test -contains "123" > False > 178# $test|foreach-object{$_.contains("123")} > True > 179# $test -contains "test 123" > True Yes they are pretty different and it is reasonable that they behave differently. $_.contains is really just System.String.Contains which was designed by the .NET Framework BCL team. Those folks have a much more strict definition of how String.Contains works which you would expect from a lower level framework type. -contains however is a PowerShell operator and PowerShell goes to great lengths to just make the operator work as you would expect it to in the face of different data types and dimensionality (scalar vs array). -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| 64 bit versus 32 bit question. | Vista General | |||
| C# versus Java | .NET General | |||
| Vista Versus XP | General Discussion | |||
| 8.5 versus 2008 versus 9 | Live Messenger | |||
| 64 bit versus 32 bit | Vista General | |||