【问题标题】:Compare two strings using Visual Studio Code?使用 Visual Studio Code 比较两个字符串?
【发布时间】:2019-08-20 21:01:52
【问题描述】:

Visual Studio Code 可用于比较文件。

"%LOCALAPPDATA%\Programs\Microsoft VS Code\code.exe" --diff file1.cs file2.cs

但是,是否可以使用它来比较存储在 PowerShell 变量中的两个文本?

$s1 = "abc
cde"
$s2 = "abc
xyz"
& "%LOCALAPPDATA%\Programs\Microsoft VS Code\code.exe" --diff ....?

Compare-Object cmdlet 仅显示两条不同的文本。文字大的时候真的没用。

【问题讨论】:

    标签: powershell visual-studio-code


    【解决方案1】:

    VSCode 只会区分文件,因此请将缓冲区保存到文件中。

    $s1 = "abc
    cde"
    $s2 = "abc
    xyz"
    
    $f1 = New-TemporaryFile
    $f2 = New-TemporaryFile
    
    $s1 | Out-File $f1.FullName
    $s2 | Out-File $f2.FullName
    
    & "C:\Program Files\Microsoft VS Code\Code.exe" --diff $f1.FullName $f2.FullName
    
    Read-Host -Prompt "Hit ENTER after you have compared temp files, and they will be deleted"
    
    Write-Host "Removing $($f1.FullName) and $($f2.FullName)"
    
    Remove-Item $f1.FullName
    Remove-Item $f2.FullName
    

    【讨论】:

      猜你喜欢
      • 2015-11-13
      • 2012-08-07
      • 2013-11-15
      • 1970-01-01
      • 2020-09-05
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多