locked
How to get byte array from string similar to System.Text.ASCIIEncoding.GetBytes

    Question

  • Hi,

    How to get a byte array from wchar* or Platform::String similar to System.Text.ASCIIEncoding.GetBytes.

    I have looked DataReader, it has a function FromBuffer(IBuffer), how to we get the IBuffer from wchar* or string.

    Thanks


    CAT
    Friday, November 04, 2011 10:25 PM

All replies

  • How about String::Data()?It will get a wchat_t type pointer.

     

    Monday, November 07, 2011 2:22 AM
  • Encoding gives nice feature of returning correct byte array based on the end-point need.
    CAT
    Monday, November 07, 2011 5:14 PM
  • I thought of returning byte array from my function, so that end-point interface can be encoding-agnostic.

    Later based on my design, it becomes internal function where it can return std::string instead of byte array or String^.  That's a kind of MSFT recommendation if data won't cross ABI, use std string instead of String^.

    However it is nice to have method of String^ to return char* (but code_page could be an issue)


    CAT
    Wednesday, November 09, 2011 8:53 PM