Part-1: Text Manipulation in PowerShell using Trim, TrimStart , TrimEnd methods
Part-2: Text Manipulation in PowerShell using .ToLower and .ToUpper method
Part-3: Text Manipulation in PowerShell using .StartsWith() and EndsWith() methods
Part-4: Text Manipulation in PowerShell using .Replace(), and .Remove() methods.
Hi,
today we are using .Contains() and .Equals() method on our text. The output of these methods is Boolean which mean either “True” or “False”
Lets start.
first set our $text variables , today we are going to use 3 variables "$text,$text2 and $text3”
$text = "The quick brown fox runs over the lazy dog"
$text2 = "Tommy is not a lazy dog"
$text3 = "The quick brown fox runs over the lazy dog"
$text.Contains("brown")
I am checking that if our $text variable contains the word “brown” in it , and yes we have “brown” word in our $text variable so the out is “True”
lets check the another example.
$text.Contains("red")
Now we are checking that if we have a “red” word in our $text variable. we know that our $text is set to “"The quick brown fox runs over the lazy dog"” and there is no “red” in it so that’s why output is false.
.Equals()
Like .Contains(), .Equals() also give output in Boolean. .Equal() method checks that both Strings are equal or not. the syntax is .Equal and provide the string to match in brackets().
Let see the examples.
here are our $text variables
$text = "The quick brown fox runs over the lazy dog"
$text2 = "Tommy is not a lazy dog"
$text3 = "The quick brown fox runs over the lazy dog"
---------
$text.Equals("$text3")
First i am checking $text and $text3 variable. as you seen $text and $text3 are identical so the output of the .Equal() is true.
Lets check $text variable with $text2 variable.
$text.Equals("$text2")
We know that $text variable and $text2 variables are not same and when we have used the .Equal method to compare both variables the output is “False”
Videos
Thanks for viewing.
Aman Dhally
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.