I use jpl files to assign Data in my DataLake.
In these text files I experience 3rd Quotes in between the original ones that mess up my allocation system.
Bsp:
dok_dat_feld_61[1]="Order **"**3000000005".
I tried a few things like:
$Variable.Replace("`"","")
$v.Trim('"')
I Expected to clean out all Quotes and Replace the originals at the beginning of the Strings but this system was very very slow especially if you have thousands of files.
I also Tried Indexing the Quotes per Line but failed due to me not knowing how to code.
2
You can try splitting in 3 parts the string and concat it again.
I try this and it works:
# Original string
$stringa = 'odok_dat_feld_61[1]="Order **"**3000000005"'
# Split the string at the second "
$parts = $stringa -split '"', 3
# Reconstruct the string without the second "
$stringa = $parts[0] + '"' + $parts[1] + $parts[2]
# Output the transformed string
Write-Output $stringa
This is my result
Write-Output $stringa
odok_dat_feld_61[1]="Order ****3000000005"
Write-Output $parts
odok_dat_feld_61[1]=
Order **
**3000000005"
1
Or use something like
# split the string on the '=' equal sign
$left, $right = ('dok_dat_feld_61[1]= "Order **"**3000000005" ' -split '=',2)
# reconstruct the line
'{0}="{1}"' -f $left, ($right -replace '"+').Trim()
Output
dok_dat_feld_61[1]="Order ****3000000005"
You can use regex to remove it, see https://regex101.com/r/Cul2Vl/1 for details.
$test = 'dok_dat_feld_61[1]="Order **"**3000000005"'
$test -replace '(?<!=)"(?!$)'
If the string was multiline, you could try with the following pattern, see https://regex101.com/r/07HXvl/1 for details.
$test = @'
text text text text
dok_dat_feld_61[1]="Order **"**3000000005"
text text text text
'@
$test -replace '(?<=="[^"]+)(?<!=)"(?!$)'