【发布时间】:2016-04-10 22:20:30
【问题描述】:
我有一个数组,用于存储用户输入的日期,但我想删除或修剪数组中输入的每个日期的前两个字符(基本上,我想删除月份):
class MainClass
{
{
//Main Program....
}
public static int GetInput (string[] date)
{
int loop;
(for int i=0 ; i < loop ; i++)
dArray[i] = Console.ReadLine();
}
}
class OtherClass
{
//Required data properties, etc...
public string TrimFirstTwoMonthChar(string dateInput)
{
char[] delimiter = {'/', '-', .... }
string[] monthNumberRemoved = dateInput.Split(delimeter);
// How would I code the rest of this function so that it removes the first 2 characters from "MM/dd/yyyy".
//Keep in mind I have also allowed users to input the date in formats like
//"M/dd/yyyy" (such as 3/07/2011 vs 03/07/2011)
//so sometimes I would only need to remove ONE NOT TWO of the month character //
}
}
【问题讨论】:
-
您需要在 cmets 中重新解释您的解释。您知道,如果您从逻辑上考虑这一点,您可以编写一些内容,如果前 2 个字符的值 mm/dd/yyyy 当然使用 substring 函数来检查长度等。
-
(for int i=0 ; i
标签: c# arrays string datetime split