locked
Is there some api to format string in c++ /cx?

    Question

  • in c# i can use System.String.Format() to deal with relative actions,and it's so convenient,

    but in c++ i can't find some way to do the same thing?

    although i can do it by myself, i just want to know is there some api to do this.

    in my scenario, i bind a textblock with a double, and want to show two number after the decimal dot,but sometimes when the number is some like 10.20, it just shows 10.2, so i want to format it to 10.20.

    Saturday, January 5, 2013 3:14 AM

Answers

  • C++/Cx is C++ so you can use your normal C++ techniques: convert the string to a C wchar_t* string and use the standard C formatting functions.

    There is a code snippet that'll get you most of the way to a formatting function in the vsnwprintf_s docs. You'll want to change it to use wchar_t*s and to  stows the buffer back in a std::wstring or Platform::String rather than printf()ing it.

    See Strings (C++/CX) for information about how strings work in C++/Cx and how to convert between various containers.

    --Rob

    • Marked as answer by waot Saturday, January 5, 2013 5:03 AM
    Saturday, January 5, 2013 3:27 AM
    Owner

All replies

  • C++/Cx is C++ so you can use your normal C++ techniques: convert the string to a C wchar_t* string and use the standard C formatting functions.

    There is a code snippet that'll get you most of the way to a formatting function in the vsnwprintf_s docs. You'll want to change it to use wchar_t*s and to  stows the buffer back in a std::wstring or Platform::String rather than printf()ing it.

    See Strings (C++/CX) for information about how strings work in C++/Cx and how to convert between various containers.

    --Rob

    • Marked as answer by waot Saturday, January 5, 2013 5:03 AM
    Saturday, January 5, 2013 3:27 AM
    Owner
  • well done, Rob, thank you , i get it~
    Saturday, January 5, 2013 5:03 AM