Click here to Skip to main content
15,917,061 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a textbox and this textbox is containing few month like apr,may,jun,jul, aug and so on.

my question is how can I show the same month as Apr to Aug for example please see below

if textbox has value like apr, may, jun then it should show as apr to Jun
if textbox has value like apr, may then it should show as apr & Jun
if textbox has value like apr, may, jun,jul,aug then it should show as apr to aug


plz help

What I have tried:

........................................................
Posted
Updated 3-Feb-17 19:33pm
v2

1 solution

Check this out:
string text = "apr,may,jun,jul,aug";
		
// Split text into array delimited by comma
string[] months = text.Split(',');
		
string result = "";
		
if (months.Length > 2)
{
	result = months[0].Trim() + " to " + months[months.Length - 1].Trim();
}
else if (months.Length > 1)
{
	result = months[0].Trim() + " & " + months[months.Length - 1].Trim();
}
else
{
	result = months[0].Trim();
}

Console.WriteLine(result);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900