- 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 to convert raw text to the CSV (Comma Separated Values) in PowerShell?
We have a raw text example and to convert it into the CSV values, we can use below code.
Example
PS C:\> $text = "This is a PowerShell latest version" PS C:\> $text.Replace(' ',',')
Output
This,is,a,PowerShell,latest,version
If there are multiple spaces between the keywords then the above replace command would go wrong. For example,
Example
PS C:\> $text = "This is a PowerShell latest version" PS C:\> $text.Replace(' ',',')
Output
This,,is,,,a,,,,PowerShell,latest,version
So we can use another method as shown below.
$text -replace '\s+',' '
In the above command, \S indicates the whitespace and + indicates the occurrence of the specific character. So more than one white space will be removed.
Next is to add the comma (,) between them so the whole command will be as below.
($text -replace '\s+',' ') -replace (' ',',')
- Related Articles
- How to convert comma separated text in div into separate lines with JavaScript?
- Find integer in text data (comma separated values) with MySQL?
- How to split comma separated values in an R vector?
- How to convert JSON to CSV file using PowerShell?
- How to convert CSV columns to text in Python?
- How to fetch random rows in MySQL with comma separated values?
- How to convert JSON file to CSV file using PowerShell?
- How to convert a comma separated String into an ArrayList in Java?
- How to convert array of comma separated strings to array of objects?
- How to search for particular strings between comma separated values in MySQL?
- Python program to convert list of string to comma separated string
- Convert String into comma separated List in Java
- Count values from comma-separated field in MySQL?
- How to count specific comma separated values in a row retrieved from MySQL database?
- Convert a List of String to a comma separated String in Java

Advertisements