wxString::Format and %



  • 1. using scrollbars with wxGLCanvas ?
    Hi all, did somebody implement wxGLCanvas with Scrollbars? I cant use wxScrolledWindow directly with wxGLCanvas. Do i have to implement all functionality (like in wxScrolledWindow) by myself? What is a simple way? mark

wxString::Format and %

Postby marcin » Sun, 18 Jun 2006 22:28:25 GMT

Format in current (13.06.2006) 2.7 version doesn't seem to handle %% as a  
literal %.

wxString number_format = wxString::Format(wxT("%%.%df"), precision);

produces: %%.1f, and it should %.1f for precision == 1. And so it does on  
my wxGTK 2.7 that is about a month old.

This started to happen some time ago (and perhaps (I'd have to update it  
but am away from that computer) works fine on FreeBSD, but perhaps there  
the system vsnprintf is being used?).

This seems to be a bug - "%%" format string should produce a single "%".

I'll try to examine wxVsnprintf and Parse in wxchar.cpp.
Marcin Simonides

To unsubscribe, e-mail:  XXXX@XXXXX.COM 
For additional commands, e-mail:  XXXX@XXXXX.COM 

Re: wxString::Format and %

Postby f18m_cpp217828 » Sun, 18 Jun 2006 23:30:41 GMT

Marcin Simonides ha scritto:
You're right - wxVsnprintf() currently fails to do this.
Since that function was rewritten by me recently, that's my fault, sorry.

I'll fix it asap.


To unsubscribe, e-mail:  XXXX@XXXXX.COM 
For additional commands, e-mail:  XXXX@XXXXX.COM 

Similar Threads:

1.Formatting double with wxString::Format


my program is compiled with MinGW on XP with wxWidgets-2.8.8.

Using wxString::Format("<%010.2f>", 3.14) I get the result
"<      3.14>" (padded with blanks).
When I use sprintf(buf, "<%010.2f>", 3.14) instead, then I get the
correct result "<0000003.14>".

Is this a bug in wxString?



3.[2.5.3] wxString::Format and unicode


wxString::Format("Text: %s", bla)
doesn't work with an unicode build. It does not compile. I know this is 
to be expected.

However, these alternatives also do not work:

wxString::Format(_("Text: %s"), bla)
wxString::Format(wxTRANSLATE("Text: %s"), bla)
wxString::Format(_T("Text: %s"), bla)
wxString::Format(wxT("Text: %s"), bla)

The program compiles, but then it hangs on that line. The only way I 
found to make it work is to use:

_("Text: ") + wxString(bla, *wxConvCurrent)

I'm not claiming that this is an error. I actually think it is not. I 
just want to suggest that the docs and the examples on 
wxString::Format() should be updated. And perhaps a way should be found 
to prevent the program to hang.

Also note that wxString::Format(_("Text: %d"), number) works fine.

Here is a code that illustrates what I'm saying. Uncomment the line 
// this doesn't work
and the program hangs, although it compiles fine:


#include <wx/wx.h>

class MyApp: public wxApp {
   virtual bool OnInit();


bool MyApp::OnInit() {

   wxString msg = _("A number: ");

   int number = 33;
   // this works:
   msg += wxString::Format(_("decimal: %d, "), number);

   char *text = "33";
   // this doesn't work:
   //  msg += wxString::Format(_("string: %s."), text);
   // but this does:
   msg += _("string: ") + wxString(text, *wxConvCurrent) + _(".");

   wxMessageBox(msg, _("wxString::Format() with Unicode"), wxOK | 
   return false;



Just dump these lines into a file and compile.



To unsubscribe, e-mail:  XXXX@XXXXX.COM 
For additional commands, e-mail:  XXXX@XXXXX.COM 

4.wxString, Format etc.

Hi folks,

what's the rationale behind wxString wrt. to converting to/from char *
etc.? Is there any at all? Why doesn't wxString::Format understand

One of the things I want to do is use wxString::Format with wxStrings.
Seems this hasn't been anticipated. Now I've tried the various
conversion functions (c_str(), char_str(), fn_str(), mb_str(),
wchar_str(), wc_str(), To8BitData()) and only c_str() seems to work,
however, the documentation says that it'll no longer work with wxWidgets 3.
What am I supposed to use then? Another thing is pathnames; I'm using
char_str() since fn_str() (which, according to the documentation, is the
proper thing to use, doesn't work.)
What's the canonical way to get anything useful out of a wxString?
Portably and without having to write special code for each combination
of OS/char width?

I'm currently using wxGTK 2.8.7 / Unicode but it should work on all
platforms (I don't care for ANSI builds).

5.Re[2]: wxString, Format etc.

6. wxString::Format way of putting commas in numbers: ie 10,000

7. CVS HEAD wxString::Format crash

8. wxString::Format and Unicode

Return to wxWindows


Who is online

Users browsing this forum: No registered users and 45 guest