Need help convert string array into single string with format

Jerry Lipan 916 Reputation points
2022-02-04T03:10:30+00:00

Hi,

Let say, I have string array as following

string[] IncidentCategoryID;  

Then, output as following,
171235-04022022-001.png

How to program in C# to convert this string array into single string like this?

('1', '3', '2')  

Make sure have

(

)

' ( single quote )

Please help

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-02-04T15:55:39.377+00:00

    var test3 = “(‘“ + string.Join(“‘ ,’”, test2) + “‘)”;

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Jose Zero 576 Reputation points
    2022-02-04T13:46:45.183+00:00

    Use system.string.join
    string[] cars = { "Volvo", "BMW", "Ford", "Mazda" };
    string carsTxt = string.Join("|", cars); // Return "Volvo|BMW|Ford|Mazda"

    0 comments No comments

  2. Jerry Lipan 916 Reputation points
    2022-02-04T19:52:11.66+00:00

    Hi @Bruce (SqlWork.com) ,

    Your guide, I adjusted as following

    var test3 = "('" + string.Join("', '", test2) + "')";  
    

    It's working

    ('1', '3', '2')  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.