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

    String character testing issue

    Scheduled Pinned Locked Moved SDK Help
    4 Posts 0 Posters 304 Views
    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 Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 11/06/2012 at 07:29, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R9.6+ 
      Platform:   Windows  ; Mac  ;  Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      Howdy,

      I had an issue with this code:

      Bool IsUsableCharacter(const String s)
      {
      	if(s >= "a" && s <= "z") return TRUE;
      	if(s >= "A" && s <= "Z") return TRUE;
      	if(s >= "0" && s <= "9") return TRUE;
      	if(s == "_") return TRUE;
      	
      	return FALSE;
      }
      

      ... where it returns FALSE for "z", "Z" and "9" if those characters are in the middle of the string but not if they are the last character in the string.

      The fix was to change the code to this:

      Bool IsUsableCharacter(const String s)
      {
      	if(s > "`" && s < "{") return TRUE;
      	if(s > "@" && s < "[") return TRUE;
      	if(s > "/" && s < ":") return TRUE;
      	if(s > "^" && s < "`") return TRUE;
      	
      	return FALSE;
      }
      

      Why doesn't the first code work?

      Adios,
      Cactus Dan

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 12/06/2012 at 00:58, xxxxxxxx wrote:

        Sorry, I can't reproduce this problem. My test code worked fine. Can you post some code where you pass strings to the functions?

        here my test code, small async dialog:

          
        #define ID_ASYNCTEST 1000955  
          
        #include "c4d.h"  
        #include "c4d_symbols.h"  
          
          
        class AsyncDialog : public GeDialog  
        {  
          private:  
          public:  
              AsyncDialog(void);  
              virtual Bool CreateLayout(void);  
              virtual Bool InitValues(void);  
              virtual Bool Command(LONG id,const BaseContainer &msg);  
        };  
          
        enum  
        {  
          IDC_TEXT = 1000  
        };  
          
        AsyncDialog::AsyncDialog(void)  
        {  
        }  
          
        Bool AsyncDialog::CreateLayout(void)  
        {  
          // first call the parent instance  
          Bool res = GeDialog::CreateLayout();  
          
          SetTitle("GuiDemo C++");  
          
          GroupBegin(0,BFH_SCALEFIT,1,1,"",0);  
          {  
              GroupBorderSpace(4,4,4,4);  
              AddEditText(IDC_TEXT, BFH_SCALEFIT, 400, 0, 0);  
          }  
          GroupEnd();  
          
          return res;  
        }  
          
        Bool AsyncDialog::InitValues(void)  
        {  
          // first call the parent instance  
          if (!GeDialog::InitValues()) return FALSE;  
          
          //SetString(IDC_TEXT, String("hello"));  
          
          return TRUE;  
        }  
          
        Bool IsUsableCharacter(const String s)  
        {  
          if(s >= "a" && s <= "z") return TRUE;  
          if(s >= "A" && s <= "Z") return TRUE;  
          if(s >= "0" && s <= "9") return TRUE;  
          if(s == "_") return TRUE;  
          
          return FALSE;  
        }  
          
        Bool AsyncDialog::Command(LONG id,const BaseContainer &msg)  
        {  
          switch (id)  
          {  
              case IDC_TEXT:  
                  String text;  
                  GetString(IDC_TEXT, text);  
          
                  LONG len = text.GetLength();  
          
                  for (LONG i=0; i<len; i++)  
                  {  
                      String subtext = text.SubStr(i, 1);  
          
                      if (IsUsableCharacter(subtext))  
                          GePrint(subtext);  
                      else  
                          GePrint("fail");  
                  }  
          
                  break;  
          }  
          return TRUE;  
        }  
          
        class AsyncTest : public CommandData  
        {  
          private:  
              AsyncDialog dlg;  
          public:  
              virtual Bool Execute(BaseDocument *doc);  
              virtual LONG GetState(BaseDocument *doc);  
              virtual Bool RestoreLayout(void *secret);  
        };  
          
        LONG AsyncTest::GetState(BaseDocument *doc)  
        {  
          return CMD_ENABLED;  
        }  
          
        Bool AsyncTest::Execute(BaseDocument *doc)  
        {  
          return dlg.Open(DLG_TYPE_ASYNC, ID_ASYNCTEST, 0, 0);  
        }  
          
        Bool AsyncTest::RestoreLayout(void *secret)  
        {  
          return dlg.RestoreLayout(ID_ASYNCTEST,0,secret);  
        }  
          
          
        Bool RegisterAsyncTest(void)  
        {  
          return RegisterCommandPlugin(ID_ASYNCTEST,GeLoadString(IDS_ASYNCTEST),0,NULL,String("C++ SDK Menu Test Plugin"),gNew AsyncTest);  
        }  
        

        cheers,
        Matthias

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 12/06/2012 at 05:48, xxxxxxxx wrote:

          Howdy,

          AHA! I was doing this:

          String subtext = text.SubStr(i, len);
          

          ... instead of like your code:

          String subtext = text.SubStr(i, 1);
          

          No wonder it wasn't working. 😊

          Adios,
          Cactus Dan

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 12/06/2012 at 07:16, xxxxxxxx wrote:

            Ah, good to hear it was a simple mistake.

            cheers,
            Matthias

            1 Reply Last reply Reply Quote 0
            • First post
              Last post