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.
Part-5: Text Manipulation in PowerShell using .Contains() and .Equals() methods
Today we are going to see what .Chars() , PadLeft() and Padright() does. And I think after covering this method there are only few methods left to cover for the next text manipulation series articles.
We are to using $text variable to show the mentioned methods.
$text = "The quick Brown fox"
ToCharArray()
The .Chars() method convert the whole string to in to the array.
$a = $text.ToCharArray()
As you can see in the below screenshot it spilt the whole string in to the single character. This is converted in to a array object.
How to check this is an array?
Okay! Let’s assign the above command to a another variable
$arr = $text.ToCharArray()
$arr[0]
$arr[1]
PadLeft()
The PadLeft() method basically added the specified number of space on the left of the sting, we need to specify how many black space we want to add in enclosed with bracket.
$text.PadLeft(200)
You can clearly see the blank spaces in the front of our original text.
.PadRight()
The .PadRight() does the same thing but I added the specified number of space to the right side of the string.
Thanks for reading :)
Aman Dhally
The padright isn't working for me :(
ReplyDelete