将字节数组转换为原始字节值的分隔字符串 [英] Converting Byte Array to delimited String of raw byte values

查看:30
本文介绍了将字节数组转换为原始字节值的分隔字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,该应用程序将监视特定注册表项值的更改并将这些更改写入文本文件.

I'm in the process of creating an application which will monitor specific registry key values for changes and write those changes to a text file.

目前我可以监控更改并知道特定值何时发生更改并收集这些值中保存的数据.我目前遇到的问题是数据的返回类型是 Byte,我希望最初将其转换为 String 以进行显示,因此我知道它返回正确的值,然后可以将其保存到文本文件中.

At present I can monitor the changes and know when specific values have changed and collect the data held in those values. The problem I'm having at the moment is the return type of the data is Byte and I wish to convert this to String initially for display so I know it returns the right value and then can be saved to a text file.

我问的原因是稍后当用户登录系统时,这些键将被创建或更改以匹配以前的值.(这样做是为了像当前使用强制配置文件一样保存用户首选项).

The reason I'm asking is that later on the next time the user logs onto a system those keys will be created or changed to match the previous values. (Were doing this as a way to save user preferences as were currently using mandatory profiles).

如果有人有任何建议,我们将不胜感激.

If anyone has any advice it would be appreciated.

推荐答案

是的,我现在已经能够通过将注册表值存储在一个字节数组中,然后将数组的每个部分添加到一个字符串中来解决这个问题,使用以下代码:

Right I've now been able to resolve this by storing the registry value in a byte array, then adding each part of the array to a string, using the following code:

RegistryKey key = Registry.Users.OpenSubKey(e.RegistryValueChangeData.KeyPath);

            Byte[] byteValue = (Byte[])key.GetValue(e.RegistryValueChangeData.ValueName);

            string stringValue = "";

            for (int i = 0; i < byteValue.Length; i++)
            {
                stringValue += string.Format("{0:X2} ", byteValue[i]);
            }

谢谢大家的建议

这篇关于将字节数组转换为原始字节值的分隔字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆