Adding a string to the verbatim string literal

前端 未结 3 811
天涯浪人
天涯浪人 2021-01-05 01:20

I have a path that is named defaultPath I want to add it into this verbatim string literal but can quite get the quotes around it.

    @\"\"\"C:\\Mavro\\Mav         


        
3条回答
  •  时光取名叫无心
    2021-01-05 01:58

    Use string.Format to insert the variable between the quotes:

    string path = "Data.Apple";
    string verbatim = string.Format(@"""C:\Mavro\MavBridge\Server\MavBridgeService.exe"" /service /data ""{0}""", path);
    MessageBox.Show(verbatim);
    

    It makes it easier to read and to implement, you can replace other portions of the path with variable sections in a similar manner.

    If you try to just append the "defaultPath" variable to the end, it will never work correctly, as you've already added the closing ".

提交回复
热议问题