Answered Format String in C++

  • miércoles, 07 de marzo de 2012 6:44
     
     

    Hi All,

            I am not using MFC in my project and also runing with UNICODE. So I can't use "CString" class in my project and CString provide many functions(Format(), reverseFind(), Left(), etc) but I need "Format()" like function for for fomating the strings.

    I am using "ICU" APIs and it provide "UnicodeString" class which can use on place of "CString", but there are few function not finding. If any one using "ICU" APIs then please tell me about "Format()" function or "Format()) like functiopn.

Todas las respuestas

  • miércoles, 07 de marzo de 2012 7:41
     
     Respondida

    I think that you can replace CString::Format with your own function that uses vswprintf or StringCchVPrintfW. As a destination buffer use the value returned by UnicodeBuffer::getBuffer(...). If the buffer is insufficient, then make a loop that tries a larger one. Then call UnicodeBuffer::releaseBuffer(-1).

    If you have the sources of ATL and MFC, then see how Format is done.

    • Editado Viorel_MVP miércoles, 07 de marzo de 2012 7:57
    • Marcado como respuesta Rob PanModerator martes, 13 de marzo de 2012 9:24
    •  
  • miércoles, 07 de marzo de 2012 12:00
     
     

    CString is no longer tied to MFC.

    Non-MFC code can still use CString by including the altstr.h header file.

    You can also use the std::wstringstream object to do similar formatting.


    «_Superman_»
    Microsoft MVP (Visual C++)

    Polymorphism in C