Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to format a string

    SDK Help
    0
    6
    457
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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++.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

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

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

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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...  
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                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);  
                }  
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post