我必须从文件中删除特殊字符和空格。句子引号之间的空格不应删除。仅需要删除字符串开头和结尾的空格。
我将输入内容保持为{}
{" fakldjfqllewfllwefklwdkf wefw " ,XCSLDKVNADUFHef328E498234750139458YefA88787 ,"&*%&*^*&^()*)(*(*T&*UKLKJGYTDUJ:" ,LMKCXXBJIUY&*(efewfqerfqerrferrferfeffgfadfgafegkEJFGI}
$objFile1 = Get-Content "D:\my-training\powershell\Sample_file.csv"
foreach($line in $objFile1)
{
$String = "$line"
$value= $String -replace '[^\p{L}\p{Nd}/"/,]', ''
Add-Content -path "D:\my-training\powershell\result.csv" -value $value
}
我将输出保持为文本格式,{}
{"fakldjfqllewfllwefklwdkfwefw",XCSLDKVNADUFHef328E498234750139458YefA88787,"TUKLKJGYTDUJ",LMKCXXBJIUYefewfqerfqerrferrferfeffgfadfgafegkEJFGI}
{"fakldjfqllewfllwefklwdkf wefw",XCSLDKVNADUFHef328E498234750139458YefA88787,"TUKLKJGYTDUJ",LMKCXXBJIUYefewfqerfqerrferrferfeffgfadfgafegkEJFGI}
问题在于,代码还删除了字符串本身中的空格,我只希望剪切开头和结尾的空格。
答案 0 :(得分:0)
嗯,这肯定是一个看起来很奇怪的字符串。 无论如何,这可以为您解决问题:
const cleanUndefined = object => JSON.parse(JSON.stringify(object));
const testWithoutUndefined = cleanUndefined(test)
输出
{"fakldjfqllewfllwefklwdkf wefw",XCSLD;KVNADUFHef328E498234750139458YefA88787,"&*%&*^*&^()*)(*(*T&*UKLKJGYTDUJ:",LMKCXXBJIUY&*(efewfqerfqerrferrferfeffgfadfgafegkEJFGI}