Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using the code below, with this code I am getting an output in decimal. What I would like to do is output this in ASCII. Not sure how to implement that in visual c++

array<Byte>^ loc= gcnew array<Byte>(18);
            serialPort1->Read(loc,0,18);
            this->richTextBox3->AppendText(String::Format("{0}{1}{2}{3}{4}{5}{6}{7}",loc[9],loc[10],loc[11],loc[12],loc[14],loc[15],loc[16],loc[17])) ;
Posted
Updated 11-Jul-11 14:24pm
v5

Use Convert.ToChar on your values, or use a format specifier. Here,[^] they are the same for all .NET languages.
 
Share this answer
 
Comments
Espen Harlinn 12-Jul-11 9:58am    
Nice and simple reply, my 5
Member 7796364 13-Jul-11 11:19am    
Thanks for the help!
C++
    array<Byte>^ loc= gcnew array<Byte>(18);
    int byteRead = serialPort1->Read(loc,0,18);

    StringBuilder builder;
    for (int i = 0; i != byteRead; ++)
    {
        // You must convert the "byte" into a "Char" to display the
        // character instead of its value (i.e. "A" instead of 65).
        Char theChar = loc[i];
        builder.Append(theChar);

        // The following line would also works (instead of the above 2).
        // builder.Append(static_cast<char>(loc[i]));
    }
    this->richTextBox3->AppendText(builder.ToString());
</char>
 
Share this answer
 
Comments
Member 7796364 13-Jul-11 11:19am    
Thank you for the help.
Forget about ASCII; .NET internally supports Unicode UTF-16. If you write .NET string to a file, you can use ASCII, of course, if all code points used are limited to 0..127. In this case, if you use UTF-8 without BOM, the output will be the same. But you're not asking about file/stream.

See:
http://en.wikipedia.org/wiki/ASCII[^],
http://en.wikipedia.org/wiki/Unicode[^],
http://unicode.org/[^],
http://unicode.org/faq/utf_bom.html[^].

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 12-Jul-11 9:58am    
Important material, my 5
Sergey Alexandrovich Kryukov 12-Jul-11 10:34am    
Thank you, Espen.
I wonder how many people still have no idea about Unicode, including those using languages rather than English.
--SA
Member 7796364 13-Jul-11 11:17am    
Reading the links, Will prove useful!
Sergey Alexandrovich Kryukov 13-Jul-11 11:34am    
Good luck!
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900