我对编程很陌生,我有一个问题,我正在尝试使用 Regex 方法从字符串中提取小时、分钟和秒并将它们放入数组中,但到目前为止我只能用一个数字来完成:
int initialDay D = 0;
string startDay = Console.ReadLine(); //input: "It started 5 days ago"
var resultString = Regex.Match(startDay, @"\d+").Value;
initialDay = Int32.Parse(resultString); // initialDay here equals 5.
Run Code Online (Sandbox Code Playgroud)
如何设法从字符串 06:11:33 中读取,并将这些小时、分钟和秒转换为整数数组?所以结果数组将是这样的:
int[] array = new int[] {n1, n2, n3}; // the n1 would be 6, n2 would be 11 and n3 would be 33
Run Code Online (Sandbox Code Playgroud)
提前感谢您的时间!