How to format a string

On 01/07/2013 at 10:34, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R13-R14 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Writing C++ plugins for C4D, how do you format a string?
I want to do this:

"The file %1 exists, do you want to overwrite?", dialogFileName.GetFileString()

But haven't found a way to do it in C++.

On 01/07/2013 at 10:48, xxxxxxxx wrote:

Take a look at MessageDialog() - there are several overrides. But to do this you will need to use a resource string (good practice anyway). Of course, it's only good for short messages, but that's often all that's needed.

On 01/07/2013 at 10:52, xxxxxxxx wrote:

c4d offers string format functionality for loading strings from the resource with geloadstring.

On 01/07/2013 at 10:54, xxxxxxxx wrote:

There are a couple of ways to do this.

Here is the first one.

  
  String = "The file " + dialogFileName.GetFileString() + " exists, do you want to overwrite?";  

Another way is to use something like  snprintf() but it is not a C4D way to do this :)

  
    
    
      char buffer [128];
      int cx = snprintf ( buffer, 128, "The file %1 exists, do you want to overwrite?", str );
  
  //TODO:  Add better way to do this...  

On 01/07/2013 at 11:33, xxxxxxxx wrote:

Originally posted by xxxxxxxx

c4d offers string format functionality for loading strings from the resource with geloadstring.

Bingo!
That's the one for me, thanks.

Originally posted by xxxxxxxx

Take a look at MessageDialog() - there are several overrides. But to do this you will need to use a resource string (good practice anyway).

Yes, I always use resource strings. 
Great tip! Just using the ID - fantastic.

On 02/07/2013 at 11:53, xxxxxxxx wrote:

Here's a quick-n-dirty "printf()" type function - just make sure that you don't overflow the buffer :)...

  
//-------------------------------------------------------------  
// GePrintF()  
//-------------------------------------------------------------  
void GePrintF(const CHAR *format,...)  
{  
 va_list arp;  
 CHAR buf[1024];  
  
 va_start(arp,format);  
 vsprintf(buf,format,arp);  
 GePrint(buf);  
 va_end(arp);  
}