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:

PS C:\> $String1='It is a Single Quoted String'  

PS C:\> $String1  

It is a Single Quoted String

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

PS C:\> $String2="It is a double Quoted String"  

PS C:\> $String2  

It is a double Quoted 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:

PS C:\> $s1="JAVAT"  

PS C:\> $s2="POINT"  

PS C:\> $s1+$s2

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

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

  1. PS C:\> $s1,$s2 -join “T”  

The output of this example will be displayed as JAVATPOINT

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

PS C:\> $s1="Power"  

PS C:\> $s2="Shell"  

PS C:\> [System.String]::Concat($s1,$s2)

The output of this example will also be displayed as PowerShell


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *