I would like to delete the string "(double quotation) using powershell.

Asked 2 years ago, Updated 2 years ago, 135 views

As per the title,
I'd like to use powershell to delete the string "(double quotation).

Current State

$s=$(get-count "c: wwork ssample.txt")
$s
$s.trim(`"`)

However, I cannot make ["] recognized.

I look forward to your kind cooperation.

powershell

2022-09-30 21:23

1 Answers

If you want PowerShell to write a string containing a double quote,

  • Use a single quote string: '
  • escape with backquote:"`"

There are methods such as .There is no backquote syntax.

In , for example:

PSC:\>$s='foobar'

PSC:\>$s
"foo bar".

US>PSC:\>$s.Trim ('"')
foobar

Reference String - Windows PowerShell|++C++;//Unidentified Flight C

Trim() is a method of removing consecutive characters at both ends of a string, so use the Replace() or the -replace operator (which uses regular expressions).

PSR:\>'a"b"c"'.Replace('",')
abc

PSR:\>'a"b"c"'-replace'"', '
abc

You can also use foreach to read multiple lines of text in Get-Contents, but you can get the same results directly using the Replace() method or the -replace operator.

PSR:\>$s
"aa"
bb"cc

PSR:\>$s | foreach {$_.Replace('', ')}
aa
bbcc

PSR:\>$s.Replace('', ')
aa
bbcc


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.