Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:58:05+00:00 2026-05-17T18:58:05+00:00

HI all I have problem when trying to convert list collection string to one

  • 0

HI all
I have problem when trying to convert list collection string to one line string.
But for each item i must edit with specific format.

Example

List<string> items = new List<string>();
string result = string.Empty;

items.Add("First");
items.Add("Second");
items.Add("Last");

result = string.Join(",", items.ToArray());
Console.WriteLine(result); // Display: First,Second,Last

But I wish to convert to something like this:

[First],[Second],[Last]

or something like

--First-,--Second-,--Last-

I know there few technique to write this code using foreach for loop.

But could it write code just change all item in list collection into specific pattern string.

So the items collections string contain like from “First” to “\First/”, or “Last” to “”Last'”.

Regard

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:58:05+00:00Added an answer on May 17, 2026 at 6:58 pm

    It sounds like you want a projection before using Join:

    result = string.Join(",", items.Select(x => "[" + x + "]")
                                   .ToArray());
    

    Personally I think that’s clearer than performing a join with a more complicated delimiter. It feels like you’ve actually got items of [First], [Second] and [Third] joined by commas – rather than items of First, Second and Third joined by ],[.

    Your second form is equally easy to achieve:

    result = string.Join(",", items.Select(x => "--" + x + "-")
                                   .ToArray());
    

    Note that you don’t need to ToArray call if you’re using .NET 4, as it’s introduced extra overloads to make string.Join easier to work with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem: We have all of our development under subversion, but our
I have problem with return statment >.< I want to store all magazine names
I have the problem, that PHP replaces all spaces with underscores in POST and
I have a problem. I'd like to match all occurrences of \t in my
I have a strange problem with VS2008. My solution has 8 projects (all c#)
I have this function to read in all ints from the file. The problem
Okay, I have ran in to a problem with VB.NET. So all those defenders
I have read through the solutions to similar problems, but they all seem to
I have this dilemma with JavaScript. I need to convert a list of dates
I'm trying to get values from xml, and I have problem with empty value.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.