PowerShell String

The PowerShell string is simply an object with a System.String type. It is a datatype that denotes the sequence of characters, either as a literal constant or some kind of variable.

A String can be defined in PowerShell by using the single or double-quotes. Both the strings are created of the same System.String object type.

Examples:

Example1: This example describes how to use the single quotes in a String:

Example2: This example describes how to use the double quotes in a String:

Concatenation

The concatenation of the string is performed using the plus Sign.

Examples:

Example1: The following example describes how to concatenate the two string variables:

The output of the last command in the above example will be displayed as tutoraspire

Example2: We can also use the join operator to join the string. The following example describes how to use this operator:

The output of this example will be displayed as tutoraspire

Example3: We can also use the method concat() to concatenate the strings. The following example describes how to use this method:

The output of this example will also be displayed as PowerShell

SubString()

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.

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.

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.

The second command in the above example displays the following output:

Windows PowerShell