powershell函数删除单行注释//


function remove-comments () {
    param
    (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [string]$line
    )
    $line = $line | Where-Object {
        -not ([String]::IsNullOrEmpty($_.Trim()) -or $_ -match "^\s*// ")
    } | ForEach-Object { $_ -replace "(.*)(// .*)", '$1' }
    return $line
} 

Get-Content $path | remove-comments
本文链接: https://www.pstips.net/remove-single-line-comment.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注