The SubString is a method which accepts the two overload arguments and returns a part of the longer string. Both the arguments are numerical values and separated by the comma (,). The left value is that value where you had like to start the SubString. The right value represents the number of characters you had like to move to the right of where you started.
Example: The following example skips the first three characters and returns the next seven-character from the given string.
PS C:\> $s1="Windows PowerShell"
PS C:\> $s1.SubString(3,7)
The second command in the above example displays the following output:
dows Po
String Formatting
String formatting is a process to insert some characters or string inside a string. We can format the string by using the -f operator.
PS C:\> $s1="Windows PowerShell"
PS C:\> $s2="POINT"
PS C:\> $formattedString = "{0} {1}...." -f $s1,$s2
PS C:\> $formattedString
The last command in the above example displays the following output:
Windows PowerShell POINT....
Replace()
The replace() method accepts the two arguments and is used to replace the characters in a string.
Example: In the following example, we can replace the character x to S in the given string.
PS C:\> $s1="Windows Powerxhell"
PS C:\> $s1.replace("x","S")
The second command in the above example displays the following output:
Windows PowerShell
Leave a Reply