C# 注册表(如何删除数组中字母之间的空格)?
这些代码允许我访问注册表并获取不可读格式的 LastvisitedMRU 值。我在这里所做的是将它们转换为可读的格式。我将它们放在一个数组中并将它们输出到控制台。
输出如下:C:\Program Files\iPod\file。 tx t
如何删除之间的空格?
提前致谢。
try
{
RegistryKey rk = Registry.CurrentUser;
rk = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU", false);
PrintKeys(rk);
}
catch (Exception MyError)
{
Console.WriteLine("An error has occurred: " + MyError.Message);
}
}
static void PrintKeys(RegistryKey rk)
{
if (rk == null)
{
Console.WriteLine("No specified registry key!");
return;
}
String[] names = rk.GetValueNames();
Console.WriteLine("Subkeys of " + rk.Name);
Console.WriteLine("-----------------------------------------------");
foreach (String s in names)
{
try
{
if (s == "MRUList")
{
continue;
}
else
{
try
{
Byte[] byteValue = (Byte[])rk.GetValue(s);
string str = BitConverter.ToString(byteValue).Replace("00", "");
str = BitConverter.ToString(byteValue).Replace("-", "");
//str binry AND VAR CONVERTED TEXT
Console.WriteLine(s + " Contains the value of : " + str);
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= str.Length - 2; i += 2)
{
sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(str.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
}
String val = Convert.ToString(sb).Replace(" ", "");
Console.WriteLine(s + " Contains the value of : " + val);
}
catch (Exception Errors)
{
Console.WriteLine("An error has occurred: " + Errors.Message);
}
}
//rk.Close();
}
catch (Exception MyError)
{
Console.WriteLine("An error has occurred: " + MyError.Message);
}
Console.WriteLine("-----------------------------------------------");
//rk.Close();
}
These codes allow me to access the registry and grab out the lastvisitedMRU values which are in a non-readable format. What I did here was to convert them into a readable format. I placed them in an array and output them into console.
The output goes like this:C : \ P r o g r a m F i l e s \ i P o d \ f i l e . t x t
How do I remove the spacings in between?
Thanks in advance.
try
{
RegistryKey rk = Registry.CurrentUser;
rk = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU", false);
PrintKeys(rk);
}
catch (Exception MyError)
{
Console.WriteLine("An error has occurred: " + MyError.Message);
}
}
static void PrintKeys(RegistryKey rk)
{
if (rk == null)
{
Console.WriteLine("No specified registry key!");
return;
}
String[] names = rk.GetValueNames();
Console.WriteLine("Subkeys of " + rk.Name);
Console.WriteLine("-----------------------------------------------");
foreach (String s in names)
{
try
{
if (s == "MRUList")
{
continue;
}
else
{
try
{
Byte[] byteValue = (Byte[])rk.GetValue(s);
string str = BitConverter.ToString(byteValue).Replace("00", "");
str = BitConverter.ToString(byteValue).Replace("-", "");
//str binry AND VAR CONVERTED TEXT
Console.WriteLine(s + " Contains the value of : " + str);
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= str.Length - 2; i += 2)
{
sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(str.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
}
String val = Convert.ToString(sb).Replace(" ", "");
Console.WriteLine(s + " Contains the value of : " + val);
}
catch (Exception Errors)
{
Console.WriteLine("An error has occurred: " + Errors.Message);
}
}
//rk.Close();
}
catch (Exception MyError)
{
Console.WriteLine("An error has occurred: " + MyError.Message);
}
Console.WriteLine("-----------------------------------------------");
//rk.Close();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那里的二进制是 unicode 编码的。我修复了你的代码并验证它可以在我的 XP 上运行。但是,它不适用于 Windows 7 或 Vista,因为 LastVisitedMRU 不再存在。
The binary there is unicode encoded. I fixed your code and verified it is working on my XP. However, it doesn't work on Windows 7 or Vista because LastVisitedMRU no longer exists.