skip to Main Content

Morning folks,
I have an ASP.Net C# page that pulls in a list of servers from a SQL box and displays the list of servers in a label. ("srv1,srv2,srv3"). I need to add double quotes around each of the servers names. ("srv1","srv2","srv3",)

Any help would be greatly appreached.

2

Answers


  1. As far as I can understand, you are trying to use double quotes in a string.
    If you want to use such,

    you can use escape character:

    (""srv1","srv2","srv3"",)
    

    for the sake of simplicity, you can even convert it to a function:

    private string quoteString(string serverName){
       return """ + serverName + """;
    }
    

    Also, if you have already "srv1,srv2,srv3" format, find ‘,’ characters in the string and add " before and after comma. Also, notice that you should add to first index and last index ".

    Login or Signup to reply.
  2. If you have string

    string str = "srv1,srv2,srv3";
    

    Then you can simply do

    str = """ + str.Replace(",", "","") + """;
    

    Now str contains "srv1","srv2","srv3"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search