![]() ![]() It doesn’t accept pipeline input and wildcard characters are not allowed. Its type is a generic list of PowerShell objects. It must be carefully observed not to leave a space after the equal sign. Alternatively, a hash table type before and after properties can be used to format the string. The source pattern is specified on the left side of the equal sign (=) and the right side denotes the target format. We can use the operator contains to check whether a powershell string array includes a string word or not.This denotes the sample format in which the output must be produced. "Hello World" -clike "*World" # return True Check Array Contains String – Ignore Case "Hello World" -like "*World" # return True Endswith – Case-Sensitive "Hello World" -clike "*world" # return False "Hello World" -like "*world" # return True "Hello World" -clike "Hello*" # return True Endswith – Ignore Caseįor ends with check, we need to put the wildcard character ( *) at the start of the string. "Hello World" -like "Hello*" # return True Startswith – Case-Sensitive "Hello World" -clike "hello*" # return False "Hello World" -like "hello*" # return True We can use the same operator “like” for starts with comparison by just putting the wildcard character ( *) at the end. "Hello World" -clike "*World*" # return True Startswith – Ignore Case "Hello World" -clike "*world*" # return False To perform a case sensitive comparison just prefix the word “c” with like operator (“clike”). ![]() Powershell array object includes ('contains') a particular object Contains Check – Case-Sensitive "Hello World" -like "*World*" # return True Note: You can not use the comparison operator contains to check the contains string, because it's designed to tell you if a "Hello World" -like "*world*" # return True We can use the -like operator for contains check with case insensitive operation. "Hello World" -ceq "Hello World" # return True Contains Check – Ignore Case "Hello World" -ceq "hello world" # return False "Hello World" -ieq "hello world" # return True Equal Check – Case-SensitiveĪs the normal powershell -eq operator is designed to perform case insensitive comparison, you may need to enforce case-sensitive string compare in some cases, for this case you can use the operator -ceq which compare two string values with case sensitive check. The usage of this operator is very less because most people use -eq which does the same job. "Hello World" -eq "Hello World" # return TrueĮven though the -eq operator performs string comparison in case-insensitive way, you may still want to ensure a case insensitive comparison for some cases, in that place you can use the operator -ieq. "Hello World" -eq "hello world" # return True The normal powershell -eq operator is designed to perform case insensitive comparison and it will ignore the case while comparing the string values. If($strVal -eq 'hello world') Equal Check – Ignore Case You can use the below examples both in IF statement and Where-Object. So in the post, I am going to list the set of samples for string comparison. We all know this is an easy job, but sometimes we need to think the comparison check is actually considering the case-sensitive or ignore case. I am also worked with string values and used lot of string compare checks in my scripts. Always there is more amount of chance to work with a string value in Powershell. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |