
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if the string contains the specific word?
To check if the PowerShell string contains a specific word, we can use the string method Contains(). For example,
Example
PS C:\> $str = 'TestNZ01LT' PS C:\> $str.Contains('NZ') True
Now the funny thing is, even if the PowerShell is case-Insensitive, the above command is not. We need to provide the exact substring. For example, the below output will be false.
Example
PS C:\> $str.Contains('Nz') False
To overcome this problem, we can either provide the same search name in the method or we need to use the lowercase or uppercase method if you don’t want the search case-sensitive.
PS C:\> $str = 'TestNZ01LT' PS C:\> ($str.ToLower()).Contains(('Nz').ToLower()) True PS C:\> ($str.ToUpper()).Contains(('Nz').ToUpper()) True
- Related Questions & Answers
- How to check if a string contains a specific sub string?
- MySQL query to check if a string contains a word?
- How to check if a string contains a certain word in C#?
- Check if the SortedSet contains a specific element in C#
- Check if the Hashtable contains a specific Key in C#
- Check if the StringDictionary contains a specific key in C#
- Check if the StringDictionary contains a specific value in C#
- Check if the Hashtable contains a specific value in C#
- How to check if any of the strings in a column contains a specific string in MySQL?
- Java Program to check if the String contains only certain characters
- Check if the String contains only unicode letters in Java
- How to check if the string ends with specific substring in Java?
- How to check if the string begins with specific substring in Java?
- Check if string contains another string in Swift
- How to use selenium to check if element contains specific class attribute?
Advertisements