Format String in C#

I have a string strnames which contains following

Tony, Ray, Arnold, Wood, Ken, Jeff: Scheduled for workshop

What I want is to hide all the names after the 3rd occurrence of comma but then display the rest of the text after the colon

So the text will be like this (three dots showing there are more people, that I want to create a hyperlink to show entire string if someone clicks on the three dots just like facebook comments they have view more button)

Tony, Ray, Arnold ... : Scheduled for workshop
LVL 11
Guru JiAsked:
Who is Participating?
Right the var is of type IEnumerable because we are using the linq .take().  If you want the string representation of this just loop through it and compile the string ( simplest way ).  So the whole bit of code would look like so:
string s = "tony, ray, arnold, wood, ken, jeff: scheudle";
string[] myArray = s.Spit(',');
var names = myArray.Take(3);
string myString = "";
foreach(var name in names){
        myString += name + ",";

//trim the last comma
var newString = myString.Remove(myString.Length - 1);

Open in new window

You could use something like this to split up the strings and take the first 3 then cocantenate the results you want together:

string s = "tony, ray, arnold, wood, ken, jeff: scheudle";
 string[] myArray = s.Split(',');
var names = myArray.Take(3);

Open in new window

Hope this helps and if you need more guidance let me know.
Guru JiAuthor Commented:
The names var does not return string like
tony, ray, arnold

How do I display only first three comma delimited values with comma in between them.
Guru JiAuthor Commented:
Hi binaryyevo,

I got it working, what I did I created two labels
label1.text = "tony, ray, arnold ... more : scheudle";
label2.text ="tony, ray, arnold, wood, ken, jeff: scheudle";
label2 is hidden by default.

How can I create that "... more" in label1 to a link which will let me hide label1 and show label2 without refreshing page.

My whole point of doing this is to hide usernames if showing more than 3 people
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.