问题描述
我有一个文本框,这个文本框包含几个月,如 apr,may,jun,jul,aug 等。
我的问题是如何显示与 4月到8月相同的月份,例如请看下面
如果textbox的值类似于 apr,may,jun 然后它应该显示为apr
如果textbox的值类似于 apr,可能那么它应显示为apr& amp; Jun
如果textbox的值类似于 apr,may,jun,jul,aug 那么它应该显示为apr到aug
plz help
我有什么尝试过:
............................ ............................
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:
........................................................
推荐答案
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);
这篇关于如何显示自定义月份winform C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!