C# Screen.PrimaryScreen.DeviceName中的字符无效
我在运行Windows XP的.Net中发现了一个bug。Screen.PrimaryScreen.DeviceName或Screen.AllScreens[]的字符串值在末尾包含空字符和内存缓冲区中的垃圾。Windows 7中不存在此问题。问题是-是否有Windows Update KB可以修复此问题 在XP上尝试以下操作:C# Screen.PrimaryScreen.DeviceName中的字符无效,c#,.net,windows-xp,C#,.net,Windows Xp,我在运行Windows XP的.Net中发现了一个bug。Screen.PrimaryScreen.DeviceName或Screen.AllScreens[]的字符串值在末尾包含空字符和内存缓冲区中的垃圾。Windows 7中不存在此问题。问题是-是否有Windows Update KB可以修复此问题 在XP上尝试以下操作: Text = string.Format("{0}: {1}", Screen.PrimaryScreen.DeviceName.Length,
Text = string.Format("{0}: {1}",
Screen.PrimaryScreen.DeviceName.Length,
Screen.PrimaryScreen.DeviceName);
通常结果是:31:\\显示1。正确的长度是12而不是31。显示1后有\0,因此字符串看起来正常,但对于字符串比较,它是错误的。这似乎是.Net/XP中的错误,Windows update无法修复。我的解决办法是:
string dev = Screen.PrimaryScreen.DeviceName;
int eos = dev.IndexOf( '\0' );
if ( eos != -1 )
dev = dev.Substring( 0, eos );