[英]Translating VB6 chars to C# strings
I want to upgrade an old VB6 project to newer technologies and I have these values below and don't know how to translate them. 我想将一个旧的VB6项目升级到较新的技术,并且下面有这些值,并且不知道如何转换它们。
Chr(&H31) & Chr(&H1) & Chr(&H50) & Chr(&H31) & Chr(&H17)
So my first question is how do I identify these? 所以我的第一个问题是如何识别这些? Is it hexadecimal values or something else?
是十六进制值还是其他? I don't seem to find them in a ascii table.
我似乎在ASCII表中找不到它们。 What does the 'H' stand for?
“ H”代表什么?
Secondly, how do I make ac# string out of this? 其次,如何从中制作ac#字符串?
Chr
converts a character code into the character, in C# you can just cast: Chr
将字符代码转换为字符,在C#中,您可以进行Chr
转换:
char c1 = (char)0x31;
(Also changing to use C#'s hexidecimal literals rather than VB6's.) (也更改为使用C#的十六进制文字而不是VB6的文字。)
But when building a string, using escapes is easier: 但是在构建字符串时,使用转义会更容易:
string s1 = "\x31\x01\x50\x31\x16";
As your "characters" include special/control/unprintable characters ( 1<SOH>P1<ETB>
), I expect this is actually non string data, and as such should not be stored as a string. 由于您的“字符”包含特殊/控制/不可打印的字符(
1<SOH>P1<ETB>
),我希望这实际上是非字符串数据,因此不应存储为字符串。
Depending on the actual desired usage, you will be better off with a byte array: 根据实际的期望用法,使用字节数组会更好:
byte[] data = new byte[] { 0x31, 0x01, 0x50, 0x31, 0x17 }
If you are not able to identify the function parameter and still wnat the same result, you can always call the native VB function from your C# application. 如果您无法识别函数参数并且仍然拥有相同的结果,则始终可以从C#应用程序中调用本机VB函数。
Microsoft.VisualBasic
Microsoft.VisualBasic
Strings.Chr
Strings.Chr
You are more confident of the result :) 您对结果更有信心:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.