Link to home
Start Free TrialLog in
Avatar of mousemat24
mousemat24

asked on

Show details based on values

Hi there

Wonder if you can help

I have these string, any of which can be blank:
private string GetContactDetails(User user)
{
  string contact = string.Format("Contact:\t{0}\r\n", user.FullName);
  string email = string.Format("Email:\t{0}\r\n", user.Email);
  string phone = string.Format("Phone:\t{0}\r\n", user.Phone);
}

what I want to to return a string based on the values above i.e.

if contact and email has a value

show:

Contact:  Rob
Email:    asdasd@hotmail.com


or if none of them have values, dont return any text


or if ONLY the phone has a value, show

Phone:    0283834757



etc


hope this makes sense?

thanks
ASKER CERTIFIED SOLUTION
Avatar of Gary Coltharp
Gary Coltharp
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
One small correction:

string contact = user.FullName == "" ? string.Empty : string.Format("Contact:\t{0}\r\n", user.FullName);
string email = user.Email == "" ? string.Empty : string.Format("Email:\t{0}\r\n", user.Email);
string phone = user.Phone == "" ? string.Empty : string.Format("Phone:\t{0}\r\n", user.Phone);
SOLUTION
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