?
Solved

I need a List<string> to render a concatenated string

Posted on 2012-03-22
5
Medium Priority
?
272 Views
Last Modified: 2012-03-22
I need a list of two string, for example, to return one string with both strings.

str1 = "Name1:
str2 = "Name2"


I'd like "Name1 and Name2"

Can  I get that from a generic list?

Thanks.
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37753131
Your question is unclear. "str1" and "str2" appear to be two separate variables. Is that correct, or are you saying that you have a generic list consisting of those two values?
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 668 total points
ID: 37753186
Is this what you want?

str1 = "Name1:"
str2 = "Name2"

mylist.Add(str1 + str2);  //concatenate the strings and add to the list of strings
0
 
LVL 9

Assisted Solution

by:gery128
gery128 earned 668 total points
ID: 37753351
you can use for each and concatenate all string variable in List<string>
Something like this: (Haven't tested below code)
StringBuilder concatendString = new StringBuilder();
foreach s in yourListName
{
     concatendString.Append(s);
}

Open in new window

0
 
LVL 7

Accepted Solution

by:
tipsybroom earned 664 total points
ID: 37753598
are the two variables in an object?

if yes:

public class myobject
{
    string str1 = "Name1:";
    string str2 = "Name2";

    public myobject() { }

    public override string ToString()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append(str1);
        sb.Append(str2);
        return sb.ToString();
    }

}

Open in new window


if you have a list of the object, it renders by self.

List<myobject> mylist;

Open in new window

0
 

Author Closing Comment

by:newbieweb
ID: 37754958
Thanks. Yes, the I wanted to find if the list inherently supports something that would create:

"list1 and list2" but it seems I will need to code it myself as you've demonstrated.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question