繁体   English   中英

如何使用Powershell将csv文件转换为小写或大写,以保持其结构?

[英]How can I convert a csv file to lowercase or uppercase maintaining it's structure using powershell?

我有一个CSV文件,其内容需要转换为所有小写字母

我已经尝试了下面的代码,但它不维护CSV结构。

(Get-Content C:\_Scratch\export.csv).ToLower() | Out-File C:\_scratch\export.csv

$Init = Import-Csv C:\_Scratch\export.csv

我还有其他选择可以尝试吗?

Get-Content将为您提供字符串数组。 添加-Raw开关以单个字符串形式读取它, .toupper().tolower()字符串方法应该可以在该字符串上工作。

(Get-Content C:\_Scratch\export.csv -Raw).ToLower() | Out-File C:\_scratch\export.csv
$TempContentArray = $NULL
$TempContent = $NULL
$TempContent = Get-Content C:\_Scratch\import.csv
Foreach ($Line in $TempContent)
{
    $TempContentArray += $Line.ToUpper()
}
$TempContentArray | C:\_scratch\export.csv
$Init = Import-Csv C:\_Scratch\export.csv

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM