- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to format string using PowerShell?
To format a string in a PowerShell we can use various methods. First using the simple expanding string method.
PS C:\> $str = 'PowerShell' PS C:\> Write-Output "Hello $str !!!!" Hello PowerShell !!!!
Second, using the format method. In this method, we will use the Format function of the String .NET class.
PS C:\> $str = "PowerShell" PS C:\> [String]::Format("Hello $str...!!!") Hello PowerShell...!!!
The third method using the Format operator. We can use the number format here as shown below.
PS C:\> $str = 'PowerShell' PS C:\> "Hello {0}" -f $str Hello PowerShell
If we have multiple variables then we need to increase the numbers inside the curly brackets. For example,
PS C:\> $str = "PowerShell" PS C:\> $str1 = "Azure" PS C:\> "Hello {0} and {1}" -f $str,$str1 Hello PowerShell and Azure
You can also use the same format operator inside the format method.
PS C:\> [String]::Format("Hello {0} and {1}", $str,$str1) Hello PowerShell and Azure
- Related Articles
- How to format date string in PowerShell?
- How to format the disk using PowerShell?
- How to convert JSON object to Hashtable format using PowerShell?
- How to convert the hashtable to the JSON format using PowerShell?
- How to Format a Date String using SimpleDateFormat in Java?
- How to get process output in GridView format in PowerShell ?
- How to convert command output to the Hashtable format in PowerShell?
- Explain JSON format in PowerShell.
- How to format JSON string in JavaScript?
- How to convert a double value into a Java String using format method?
- How to format a string to date in as dd-MM-yyyy using java?
- How to traceroute using PowerShell?
- How to compare Python string formatting: % with .format?
- How to change the format of the URL string of IText object using FabricJS?
- How to format a date to String in Java?

Advertisements