- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 does string formatting work in PowerShell?
To format string in PowerShell, you can use -F operator. When you use -F format, you need to provide the argument number in the curly brackets.
Example
PS C:\> $Str = "Hello PowerShell" PS C:\> "{0}" -f $str Hello PowerShell
For the multiple values,
PS C:\> $Str = "Hello PowerShell" PS C:\> $str1 = "Rockstart" PS C:\> "{0} says {1}" -f $Str,$str1 Hello PowerShell says Rockstart
From the above example, we understood if we need to get the output for multiple variables using the -F operator then we can increment the number in curly brackets.
To use the above output with the Write-Output command,
PS C:\> Write-Output "{0} says {1}" -f $str,$str1 {0} says {1} -f Hello PowerShell Rockstart
If we use the above method, the output will be messed up so to get the output in the correct format, we need to use the round bracket with Write-Output as shown below.
PS C:\> Write-Output ("{0} says {1}" -f $str,$str1) Hello PowerShell says Rockstart
- Related Articles
- How does PowerShell Remoting work?
- How does PowerShell Pipeline work – Part 1?
- How does PowerShell Pipeline work – Part 2?
- Explain HTML formatting in PowerShell?
- Explain output formatting PowerShell
- String Formatting in Python using %?
- String Formatting Operator in Python
- String Formatting in C# using %
- String Formatting in Java using %
- How does jQuery.scrollTop() work?
- How does jQuery.scrollLeft() work?
- How does classification work?
- How does backpropagation work?
- How does RSA work?
- How does React work?

Advertisements