Link to home
Start Free TrialLog in
Avatar of Guru Ji
Guru JiFlag for Canada

asked on

Format String in ASP.net 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
Avatar of binaryevo
binaryevo
Flag of United States of America image

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.
Avatar of Guru Ji

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of binaryevo
binaryevo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guru Ji

ASKER

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