Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting strings and case sensitivity

Tags:

powershell

I am trying to filter for an object that has a Title field, and I want to ignore case. Is there a way to make sure case sensitivity if turned off?

| Where-Object {$_.Title -like "myString"} 
like image 768
ChiliYago Avatar asked Mar 12 '10 22:03

ChiliYago


2 Answers

PowerShell is fundamentally case insensitive (e.g. "HEy" -like "hey" is True).

If you want to use the case sensitive version of like, use -clike.

like image 68
Chris Ortiz Avatar answered Oct 05 '22 03:10

Chris Ortiz


By default case sensitivity is off:

PS> 'test','TEST','TeSt','notest' | ? { $_ -like 'test' } test TEST TeSt 

From documentation:

By default, all comparison operators are case-insensitive. To make a comparison operator case-sensitive, precede the operator name with a "c". For example, the case-sensitive version of "-eq" is "-ceq". To make the case-insensitivity explicit, precede the operator with an "i". For example, the explicitly case-insensitive version of "-eq" is "-ieq".

For more information run help about_comparison_operators

like image 32
stej Avatar answered Oct 05 '22 02:10

stej