Re: Convert from byte array to string

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

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 11/04/04


Date: Thu, 4 Nov 2004 10:42:44 -0500

Ricardo,

    I understand, but you are using ASCII encoding. I also think that the
code page that you are using is wrong, and that is the case. Do you know
the code page of the machine that you are on that is processing the code?

-- 
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com
"Ricardo Quintanilla" <RicardoQuintanilla@discussions.microsoft.com> wrote 
in message news:16CAD5E1-C649-423C-8191-8CED363CD779@microsoft.com...
> First all, thanks Nicholas.
>
> i have no problem with the data sent to as400 socket, my problem is with 
> the
> data received as response when i try to convert it from "byte array" to
> string, some characters are wrong converted.
>
> i am using the NetworkStream class in order to send/receive data over a
> TcpClient instance class.
>
> how can i apply your advice?
>
> -- 
> Ricardo Quintanilla G.
>
>
>
> "Nicholas Paldino [.NET/C# MVP]" wrote:
>
>> Ricardo,
>>
>>     It would seem to me that you are using the wrong encoding, or you 
>> need
>> to specify the correct code page for the encoder.  Are you sure that the
>> bytes being sent are ASCII encoded?
>>
>>
>> -- 
>>                - Nicholas Paldino [.NET/C# MVP]
>>                - mvp@spam.guard.caspershouse.com
>>
>> "Ricardo Quintanilla" <RicardoQuintanilla@discussions.microsoft.com> 
>> wrote
>> in message news:5C9EB410-9D3E-4A58-B635-CFDA1457B92F@microsoft.com...
>> >i have a code that sends data to a socket listening over as400 platform,
>> > the socket responds to me as a "byte array".
>> >
>> > then i need to convert the "byte array" into a string.
>> > the problem is that the data converted from the byte array into a 
>> > string
>> > , is not what i expect.
>> >
>> > example:
>> > - the data returned from the socket is (byte array)
>> > "Usuario Sin Atribuciones Para Esta Función"
>> >
>> > - the data obtained from the convert process is (a string)
>> > "Usuario Sin Atribuciones Para Esta Funcisn"
>> >
>> > look at the last word, it have an accent, but when i convert it, the
>> > accent
>> > is loosed.
>> >
>> >
>> > i am using then next code, in order to convert the byte array to string
>> >
>> > -----------------------------------------------------------------------
>> > string dataReceivedinText = 
>> > Encoding.ASCII.GetString(bytesDataReceived);
>> > -----------------------------------------------------------------------
>> >
>> > what can i do, in order to solve my problem?
>> > any suggestion?
>> >
>> > many thanks
>> >
>> >
>> > -- 
>> > Ricardo Quintanilla G.
>>
>>
>> 


Relevant Pages

  • Re: Convert from byte array to string
    ... i have no problem with the data sent to as400 socket, ... Ricardo Quintanilla G. ... >> the socket responds to me as a "byte array". ... >> then i need to convert the "byte array" into a string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TCP/IP Sockets with GNAT.Sockets
    ... the problem is the use of attributes 'Output on arrays which output array bounds before array data. ... and since String is an array, String'Output outputs String bounds before string data. ... you should note that the problem is the same in C: when reading a string from a socket, ... Streams while a Socket package isn't required to give any explanations ...
    (comp.lang.ada)
  • Re: Convert from byte array to string
    ... >i have a code that sends data to a socket listening over as400 platform,> the socket responds to me as a "byte array". ... > the problem is that the data converted from the byte array into a string>, ... > look at the last word, it have an accent, but when i convert it, the> accent ...
    (microsoft.public.dotnet.languages.csharp)
  • Convert from byte array to string
    ... the socket responds to me as a "byte array". ... then i need to convert the "byte array" into a string. ... look at the last word, it have an accent, but when i convert it, the accent ...
    (microsoft.public.dotnet.languages.csharp)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)