创建十六进制字符串以在网络流上发送 [英] create hex-string to send on networkstream

查看:57
本文介绍了创建十六进制字符串以在网络流上发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我需要发送一些NUL - > HEX值00。在网络流上..


这是我们目前用来发送字符串的代码:

Dim sendBytes As [Byte]()= Encoding.ASCII.GetBytes (inputtext.ToString)

networkStream.Write(sendBytes,0,sendBytes.Length)

由于hex 00(NUL)没有char值,所以它不是可以使用

字符串作为输入..

谢谢,

Sven

Hello,

I need to send a couple of "NUL"s -> HEX value "00" on a networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it''s not possible to use a
string as input..
Thanks,
Sven

推荐答案

" Sven Huijbrechts" < SV ** @ no-spam-hts.be> schrieb
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
我需要发送一些NUL - > HEX值00。在网络流上..
这是我们目前用来发送字符串的代码:
Dim sendBytes As [Byte]()=
Encoding.ASCII.GetBytes (inputtext.ToString)
networkStream.Write(sendBytes,0,sendBytes.Length)

由于十六进制00(NUL)没有char值,所以不可能
使用字符串作为输入..
I need to send a couple of "NUL"s -> HEX value "00" on a
networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it''s not possible to
use a string as input..




为什么没有char值? chr(0)返回这样一个char。不要使用ASCII

编码,因为ASCII = 7位。你想发送字符的十六进制字符串表示

的字符代码,或者你想发送

字符代码本身?什么是输入文字?它包含什么

例如?

一种可能的解决方案:

Dim sendBytes As Byte()''no []这里需要

sendBytes = Encoding.Default.GetBytes(inputtext.ToString)

networkStream.Write(sendBytes,0,sendBytes.Length)


Encoding.Default返回当前的ANSI代码页(8位字符代码)。


另一种解决方案取决于上述问题的答案。


也许您可以使用Streamwriter。您可以将编码一次性传递给构造函数,而不必自己转换每个字符串。


-

Armin

http:// www。 plig.net/nnq/nquote.html
http ://www.netmeister.org/news/learn2quote.html



Why is there no "char value"? chr(0) returns such a char. Don''t use ASCII
encoding because ASCII = 7 bits. Do you want to send the character codes of
the hexadecimal string representation of the chars, or do you want to send
the character codes themselves? What is "inputtext"? What does it contain
for example?

One possible solution:
Dim sendBytes As Byte() ''no [ ] required here
sendBytes = Encoding.Default.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)

Encoding.Default returns the current ANSI codepage (8-Bit character codes).

The other solution depends on the answers to the questions above.

Maybe you can use a Streamwriter instead. You could pass the encoding once
to the constructor and don''t have to convert each string on your own.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


" Sven Huijbrechts" < SV ** @ no-spam-hts.be> schrieb
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
我需要发送一些NUL - > HEX值00。在网络流上..
这是我们目前用来发送字符串的代码:
Dim sendBytes As [Byte]()=
Encoding.ASCII.GetBytes (inputtext.ToString)
networkStream.Write(sendBytes,0,sendBytes.Length)

由于十六进制00(NUL)没有char值,所以不可能
使用字符串作为输入..
I need to send a couple of "NUL"s -> HEX value "00" on a
networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it''s not possible to
use a string as input..




为什么没有char值? chr(0)返回这样一个char。不要使用ASCII

编码,因为ASCII = 7位。你想发送字符的十六进制字符串表示

的字符代码,或者你想发送

字符代码本身?什么是输入文字?它包含什么

例如?

一种可能的解决方案:

Dim sendBytes As Byte()''no []这里需要

sendBytes = Encoding.Default.GetBytes(inputtext.ToString)

networkStream.Write(sendBytes,0,sendBytes.Length)


Encoding.Default返回当前的ANSI代码页(8位字符代码)。


另一种解决方案取决于上述问题的答案。


也许您可以使用Streamwriter。您可以将编码一次性传递给构造函数,而不必自己转换每个字符串。


-

Armin

http:// www。 plig.net/nnq/nquote.html
http ://www.netmeister.org/news/learn2quote.html



Why is there no "char value"? chr(0) returns such a char. Don''t use ASCII
encoding because ASCII = 7 bits. Do you want to send the character codes of
the hexadecimal string representation of the chars, or do you want to send
the character codes themselves? What is "inputtext"? What does it contain
for example?

One possible solution:
Dim sendBytes As Byte() ''no [ ] required here
sendBytes = Encoding.Default.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)

Encoding.Default returns the current ANSI codepage (8-Bit character codes).

The other solution depends on the answers to the questions above.

Maybe you can use a Streamwriter instead. You could pass the encoding once
to the constructor and don''t have to convert each string on your own.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


*" Sven Huijbrechts" < SV ** @ no-spam-hts.be> scripsit:
* "Sven Huijbrechts" <sv**@no-spam-hts.be> scripsit:
由于十六进制00(NUL)没有char值,因此无法使用
Since there is no char value for hex 00 (NUL) it''s not possible to use a


字符串作为输入..


string as input..




?!?


您可以使用''ControlChars.NullChar''获取空字符。


-

Herfried K. Wagner [MVP]

< http://www.mvps.org/dotnet>



?!?

You can use ''ControlChars.NullChar'' to get a null character.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


这篇关于创建十六进制字符串以在网络流上发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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