我有一个日期戳 (020920111422),我想将它拆分为
天 = 02, 月 = 09, 年 = 2011, 小时 = 14, 分钟 = 22
C#中有“在位置处拆分字符串”的方法吗?
最佳答案
你想要:
string x = s.Substring(0, i), y = s.Substring(i);
(或者可能是 i-1/i+1,具体取决于您的具体要求)。
但是,您也可以使用 DateTime.ParseExact
通过告诉它显式格式将其加载到 DateTime
中:
var when = DateTime.ParseExact("020920111422", "ddMMyyyyHHmm",
CultureInfo.InvariantCulture);
关于c# - 在 C# 中的位置拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7386298/