【问题标题】:How to add "" in to string.Format in C# [duplicate]如何在 C# 中将“”添加到 string.Format [重复]
【发布时间】:2021-01-05 01:01:30
【问题描述】:

我需要将文件夹路径传递给 Python 界面,但路径中的空格使其变得复杂。 例子 : Defect.py C:\TestImage\Images 工作正常。 但是,如果如下路径中有空格,

`Defect.py C:\**Test Image**\Images`

由于两个单独的参数而导致错误。

如果我可以将其传递为: Defect.py "C:\**Test Image**\Images" 应该可以工作

所以我目前正在尝试使用string.Format("{0}") 用双引号格式化此字符串,但不起作用。 请让我知道如何使用string.Format 格式化语句。我需要使用 string.Format 因为还有多个其他参数。

【问题讨论】:

    标签: c# string format


    【解决方案1】:

    试试这个:

    string.Format("Defect.py \"C:\\{0}\\Images\"", "Test Image");
    

    请记住,整个技巧是使用\" 反斜杠转义字符来转义字符。剩下的只是展示如何使用string.Format

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 2016-10-12
      相关资源
      最近更新 更多