【问题标题】:Facing problem in Variable Transformation in VS Code snippets [duplicate]VS代码片段中变量转换面临的问题[重复]
【发布时间】:2021-11-23 13:22:05
【问题描述】:

我有以下VS Code的global-sn-p代码

"prints formated path": {
    "prefix": "pp",
    "body": [
        "$BLOCK_COMMENT_START",
        "File Path ->     \"${TM_FILEPATH/\\///g}\"",
        "$BLOCK_COMMENT_END",
    ],
    "description": "prints path"
},

上面sn-p的输出是

"""
File Path ->     "D:\tp\New folder (6)\4. Chapter 4 Packaging\my_package\test.py"
"""

预期的输出是

"""
File Path ->     "D:/tp/New folder (6)/4. Chapter 4 Packaging/my_package/test.py"
"""

其实我想把 '\' 换成 '/'

在网上搜索太多后,我找到了this page,它谈到了Variable Transformation in VS Code,但它对我没有帮助。 如果您知道问题的解决方案,请提出建议

【问题讨论】:

    标签: visual-studio-code replace path vscode-snippets


    【解决方案1】:

    问题是正则表达式的解析,你必须添加一个捕获组来识别反斜杠,你必须转义替换斜杠

      "prints formated path": {
        "prefix": "pp",
        "body": [
            "$BLOCK_COMMENT_START",
            "File Path ->     \"${TM_FILEPATH/(\\\\)/\\//g}\"",
            "$BLOCK_COMMENT_END",
        ],
        "description": "prints path"
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 1970-01-01
      相关资源
      最近更新 更多