当我尝试像这样解析日期时:
DateTime t1 = DateTime.ParseExact("August 11, 2013, 11:00:00 PM", "MMMM dd, yyyy, hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture);
它工作正常,但是当我这样做时:
string s ="August 11, 2013, 11:00:00 PM";
DateTime t = DateTime.ParseExact(s, "MMMM dd, yyyy, hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture);
我收到这个错误:
An exception of type 'System.FormatException' occurred in mscorlib.ni.dll but was not handled in user code
最佳答案
因为你的字符串
string s = "August 11, 2013, 11:00:00 PM";
包括0x200e(8206) character在 8 月
的开始和结束。你可以很容易地看到它
var chars = s.ToCharArray();
好像是复制+粘贴的问题
您可以通过以下方式删除这些字符:
var newstr = new string(s.Where(c => c <128).ToArray())
关于c# - 解析字符串时出现奇怪的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18298208/