locked
convert a byte to string RRS feed

  • Question

  • User-507786106 posted

    How do I convert a byte to a string?

    status is a string variable
    Obj.Status is a tinyint

    Status = Obj.Package_Status; <-- make a string
    

    Wednesday, March 25, 2015 3:46 PM

Answers

All replies

  • User-434868552 posted

    @slimbunny

    String status = "1234";
    Byte   cityStatus;
    Boolean goodValue = Byte.TryParse(status, out cityStatus);
    if(goodValue) Console.WriteLine (cityStatus);
    else Console.WriteLine ("Status ["+ status + "] rejected");

    output:

    Status [1234] rejected

    study https://msdn.microsoft.com/en-us/library/f78h0es7(v=vs.110).aspx "Byte.TryParse Method (String, Byte)"

    edit:

    sorry, my answer was the opposite to your question ... Byte to String is easy:

    String status;
    Byte   cityStatus = 255;
    status = cityStatus.ToString();
    Console.WriteLine (status);

    output:

    255

    see https://msdn.microsoft.com/en-us/library/system.byte.tostring(v=vs.110).aspx "Byte.ToString Method"


    end edit.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 25, 2015 4:07 PM
  • User-369506445 posted

    hi

    please try below code :

    string status= System.Text.Encoding.UTF8.GetString(byteArray);
    

    Thursday, March 26, 2015 3:57 AM