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
Today we are using .replace and .remove methods to play with the string. Lets start. Today i am using some fake email id as text.
$text = Aman.Dhally@xyz.com
Using replace we can replace the text,symbols of our strings. The syntax is simple Replace(“Old Character”,”new character”)
First lets replace “Aman” with some other name , for example with “SAM”,"
Secondly lets replace “.” with a blank spaces
lets assume that we have a text file which contain list of all users email id in our “XYZ” company and we want to remove “@xyz.com” and keep the text before “@xyz.com” .
Before doing anything else first lets check the length of our text using Length property. The syntax for remove method is to define to keep the number of characters and remove everything else. Not getting my point.. let ,me show to you.
Our text have 19 characters in it.
Now i am keeping 11 characters of the string and removing everything else. and you can see that the output is “Aman.Dhally” which are exactly 11 characters .
there is another example of Remove() method.
In this example. first you can see our original text “Aman.Dhally@xyz.com”, in second we are keeping the first 4 characters of the text and removing everything else, so the output is “Aman”, in third we are keeping first 4 characters of the text "which is “AMAN”, and then removing next 7 characters of the text which is “.Dhally” and then the output is “Aman@xyz.com”
Thanks for reading