Did you ever tried to use .Trim() method on a string and can’t get it working? if yes ? Then welcome to the novice group. and if no? man you are genius.
i was looking for some example for it i found few but not with screenshots :) .. then i decide to write a article on it …
So lets start.
I am using the text “The Quick brown fox jumps over the lazy dog” and put this text in to a variable $text
You can see that i have a space in the the beginning of the text and the end of the text.
Lets remove these spaces to remove these spaces we are going to use trim() method.
The Trim() remove the black characters to the right and left
You can see that white space is removed from beginning of “the quick brown”
The TrimStart() remove all the chracters from the start of the string.
If you want to remove any from the beginning of the text than we need to use TrimStart() method. Lets remove “The QUick” from the text.
Now you can see in the output “The QUick” is removed from output.
not lets trim the end of the string using TrimEnd() method
The TrimEnd() remove are the characters from the string.
$text.TrimEnd("the lazy dog. ")
You can see that now “the lazy dog.” is removed from the output.
I hope this helps someone…