本文介绍了从system.byte []转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有WMP11 SDK的这段代码返回了错误的值.

Case CreateEditor.WMT_ATTR_DATATYPE.WMT_TYPE_GUID
tagValue ="{"&BitConverter.ToString(attribValue)&}"

''tagValue = BitConverter.ToString(attribValue,0,attribValue.Length)
''tagValue = Convert.ToBase64String(attribValue)
''tagValue = System.Text.UnicodeEncoding.ASCII(attribValue)
''tagValue = Encoding.ASCII.GetString(attribValue)
''tagValue = Encoding.Unicode.GetString(attribValue)
''tagValue = Encoding.UTF8.GetString(attribValue)

我已经评论了我尝试过的其他内容.其中大多数返回乱码.
attribValue.tostring返回{System.Byte []}.

上面的代码(bitconverter.tostring)返回{BC-7D-60-D1-23-E3-E2-4B-86-A1-48-A4-2A-28-44-1E-00}.

我还有另一个使用AxInterop.WMPLib的应用程序,它应返回{D1607DBC-E323-4BE2-86A1-48A42A28441E}.

关于我可以尝试的任何建议吗?
有没有办法确定使用了哪种编码器?

谢谢

I have this bit of code from WMP11 SDK that returns an incorrect value.

Case CreateEditor.WMT_ATTR_DATATYPE.WMT_TYPE_GUID
tagValue = "{" & BitConverter.ToString(attribValue) & "}"

'' tagValue = BitConverter.ToString(attribValue, 0, attribValue.Length)
'' tagValue = Convert.ToBase64String(attribValue)
'' tagValue = System.Text.UnicodeEncoding.ASCII(attribValue)
'' tagValue = Encoding.ASCII.GetString(attribValue)
'' tagValue = Encoding.Unicode.GetString(attribValue)
'' tagValue = Encoding.UTF8.GetString(attribValue)

I have commented out other things I have tried. Most of them return gibberish.
attribValue.tostring returns {System.Byte[]}.

The above code (bitconverter.tostring) returns {BC-7D-60-D1-23-E3-E2-4B-86-A1-48-A4-2A-28-44-1E-00}.

I have another app that uses AxInterop.WMPLib and it returns {D1607DBC-E323-4BE2-86A1-48A42A28441E} as it should.

Any suggestions on what I might try?
Is there a way to determine what encoder was used?

Thank you

推荐答案

Yoda 写道:

执行或不执行.没有尝试.

Do or Do not. There is no try.

请参阅: http://www.youtube.com/watch?v=q3hn6fFTxeo [ ^ ].

请看我对这个问题的评论.这是没有意义的,因为除了您之外,没有人知道将什么实际编码(序列化)为字节数组.这不是编程问题,应该在本论坛中提出,而是纯粹的重复. :-)

但是,当您提供一些间接信息和预期结果时,让我们尝试猜测可能是什么.编码值可能不是字符串.它可以是GUID,但不能为字符串形式.顺便说一句,您通常应该养成使用数据的习惯,而不是字符串表示形式.因此,假设这是GUID,您可以尝试使用BitConverter ,将字符数组反序列化为GUID. ,请参阅:
http://msdn.microsoft.com/en-us/library/system.guid.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.bitconverter.aspx [^ ].

如果可行,则应使用此GUID值.您只需要字符串即可将其显示在文本文件中,在屏幕上显示等.与其他任何数据一样,您将需要ToString方法之一.

—SA

Please see: http://www.youtube.com/watch?v=q3hn6fFTxeo[^].

Please see my comment to the question. This is pointless, because no one except you knows what was actually encoded (serialized) as an array of byte. This is not a programming question, as it should be pose in this forum, but a pure rebus. :-)

However, as you provided some indirect information and the expected result, let''s try to guess what it could be. The encoded value was probably not a string. It could be GUID, but not in the string form. By the way, you should generally get a habit to work with data, not its string representation. So, assuming this is GUID, you could try to deserialize you array of chars as GUID, per component using BitConverter , please see:
http://msdn.microsoft.com/en-us/library/system.guid.aspx[^],
http://msdn.microsoft.com/en-us/library/system.bitconverter.aspx[^].

If this works, you should just work with this GUID value. You only need string to present it in a text file, show on screen, etc. As with any other data, you would need one of ToString methods.

—SA


这篇关于从system.byte []转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:33