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

    The String Class

    Scheduled Pinned Locked Moved SDK Help
    2 Posts 0 Posters 131 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 15/07/2012 at 10:41, xxxxxxxx wrote:

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

      ---------
      Hi,

      I'm going through the string class and writing out small working examples of each string function. So I don't have to figure them out while I'm in the middle of a project. And I'm not getting the expected results from ComparePart() & RelCompare();
      They are producing strange values(36&100,000). When they should be producing zero(I think).

      Here's what I've got.
      I'm comparing two strings with the same values then running each of the string functions on them:

          String s1 = "Hello there";                    //The string we will work on  
        LONG len = s1.GetLength();                    //Get the length of the string  
        
        LONG Fpos = NULL;                             //This will hold the position of a string in the text  
        LONG Lpos = NULL;                             //This will hold the position of a string in the text  
        Bool firstfound = s1.FindFirst("ll",&Fpos,1); //Finds the first occurance of "ll" and stores it's position in the string in "Fpos"  
        Bool lastfound = s1.FindLast("e",&Lpos,-1);   //Finds the last occurance of "e" and stores it's position in the string in "Lpos"  
        GePrint("First Position in the string= " + LongToString(Fpos));  
        GePrint("Last Position in the string= " +LongToString(Lpos));  
        
        String sub = s1.SubStr(2,2);         //Gets "ll" characters in the word Hello  
        GePrint("SubString= " + sub);  
          
        String s2 = "Hello there";           //A second string we'll use to compare to the original string  
        LONG comp = s1.Compare(s2);          //Compares two strings and returns zero if the two strings are exactly the same (Case sensitive)  
                                             //If the second string is shorter than the original. It will return positive values  
                                             //If the second string is longer than the original. It will return negative values  
        GePrint("StringsEqual?: " + LongToString(comp));       
        
        LONG lexcomp = s1.LexCompare(s2);    //Compares two strings and returns zero if the two strings are exactly the same (NOT case sensitive)  
                                             //If the second string is shorter than the original. It will return positive values  
                                             //If the second string is longer than the original. It will return negative values  
        GePrint("StringsEqual?: " + LongToString(lexcomp));  
        
        LONG comppart = s1.ComparePart(s2, 2, 2);          //Returns 36!?<--------------Why not zero?  
        //LONG comppart = sub.Compare(scopy);              //Also Returns 36!?  
        GePrint("PartEqual?: " + LongToString(comppart));  
        
        LONG relcomp = s1.RelCompare(s2);                  //Returns 100,000!?<-------Why not zero?  
        GePrint("RelPartEqual?: " + LongToString(relcomp));
      

      I'm wondering why I'm not getting zero for those two functions as expected?
      And what those numbers(36 & 100,000) mean?

      -ScottA

      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 15/07/2012 at 12:58, xxxxxxxx wrote:

        I managed to solve the ComparePart() function.
        I was thinking the last two params. were for the target string. But they are actually for the source string.

        But I still can't figure out why RelCompare() does not return zero for two strings with the same value.

        Here's the updated code:

          
          
          String s1 = "Hello there";                    //The string we will work on  
          LONG len = s1.GetLength();                    //Get the length of the string  
          
          LONG Fpos = NULL;                             //This will hold the position of a string in the text  
          LONG Lpos = NULL;                             //This will hold the position of a string in the text  
          Bool firstfound = s1.FindFirst("ll",&Fpos,1); //Finds the first occurance of "ll" and stores it's position in the string in "Fpos"  
          Bool lastfound = s1.FindLast("e",&Lpos,-1);   //Finds the last occurance of "e" and stores it's position in the string in "Lpos"  
          GePrint("First Position in the string= " + LongToString(Fpos));  
          GePrint("Last Position in the string= " +LongToString(Lpos));  
          
          String sub = s1.SubStr(2,2);         //Gets "ll" characters in the word Hello  
          GePrint("SubString= " + sub);  
            
          String s2 = "Hello there";           //A second string we'll use to compare to the original string  
          LONG comp = s1.Compare(s2);          //Compares two strings and returns zero if the two strings are exactly the same (Case sensitive)  
                                               //If the second string is shorter than the original. It will return positive values  
                                               //If the second string is longer than the original. It will return negative values  
          GePrint("StringsEqual?: " + LongToString(comp));       
          
          LONG lexcomp = s1.LexCompare(s2);    //Compares two strings and returns zero if the two strings are exactly the same (NOT case sensitive)  
                                               //If the second string is shorter than the original. It will return positive values  
                                               //If the second string is longer than the original. It will return negative values  
          GePrint("StringsEqual?: " + LongToString(lexcomp));  
          
          
          String s3 = "ll";  
          LONG subcomp = sub.Compare(s3);                    //Returns zero when the string referenced in the params(s3) exactly matches the sub string's value   
          GePrint("SubEqual?: " + LongToString(subcomp));  
          
          String s4 = "ll";                                  //s4 is the target...s1 is the source    
          LONG comppart = s1.ComparePart(s4, 2, 2);          //param1 is the target...param2 is the number of source chars to compare...param3 is the position in the source to start comparing     
          GePrint("PartEqual?: " + LongToString(comppart));  
          
          LONG relcomp = s1.RelCompare(s2);                  //Returns 100,000!?<-------Why not zero?  
          GePrint("RelPartEqual?: " + LongToString(relcomp));  
          
          
          char ch[] = {"tB"};                              //The target  
          String str = "BBt";                              //The source  
          LONG source = str.ComparePart(String(ch),1,2);   //Compares two strings and returns zero if the two strings are exactly the same. Postions start at zero like array index's  
                                                           //param1 is the target...param2 is the number of source chars to compare...param3 is the position in the source to start comparing    
          GePrint("chPartEqual?: " + LongToString(source));
        

        -ScottA

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