Re: Converting a string to an array of bytes.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

youv'e got to use the right Encoding. for your problem the codepage of the
System should work.

try:
bytes = System.Text.Encoding.Default.GetBytes(inputstring);

hth

"Riaan" <Riaan@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:027DBBDE-1433-4700-87E9-8ED0B01D2252@xxxxxxxxxxxxxxxx
Hi,

I am working on an app where I need to get user input which defines an
rs232
based protocol.

The user must be able to type in a string of characters that include non
standard keyboard characters such as aschii charater 159.

In the old VB apps I worked one could type into a text box something like
alt+159 (displayed as 'f') and when converting that string to a byte array
you would get an array with one element with the byte value 159.

Now, using C#, I can not for the love of money do the same. When I do the
converson I get an array with bytes that contain more bytes than the
number
of characters in the original string and none of these byte values are the
correct ones.

--
I have a plan so cunning you could pin a tail on it and call it a weasel.


.



Relevant Pages

  • Re: Help a beginner - simple lowercase to uppercase and so on function
    ... And then one to loop across the string calling that function ... copying at to a new array. ... are any characters other than lowercase letters */ ...
    (comp.lang.c)
  • Re: fgets question
    ... documentation didn't say if fgets put \0 after a string literal. ... fgets() has nothing at all to do with string literals. ... within the bounds of the array, then it is not a string. ... strlenon an array of characters that is not a string, ...
    (comp.lang.c)
  • Re: left$, mid$ and right$ (was: ANN: pldev.org)
    ... I avoided saying an array of characters ... used option and discuss a string as an array of characters. ... (Similar could be said of a list if the language ...
    (comp.lang.misc)
  • Re: newbie: mapping CHARACTER*2 to INTEGER*2
    ... that destroys the Chinese characters in my input. ... effect the conversion required. ... If MOLD is an array and SIZE is omitted, ... represent the values 4.0 and 1082130432 as the string of binary digits ...
    (comp.lang.fortran)
  • Re: Help creating a random string in Perl
    ... can pick one of the 7 characters in my source string) by using "print ... third and fourth characters to and check that the random number hasn't ... shuffling the array ... The idea here is to swap the current cell with some cell ...
    (perl.beginners)