String::FindFirst()



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

    On 28/03/2007 at 13:20, xxxxxxxx wrote:

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

    ---------
    Hi Guys,
    I am unable to get the FindFirst member function of the String class to operate correctly. The following code should work, but doesn't:

        
        
        
        
        LONG *charPos = NULL;  
        String name("Cube Whatever");
        
        
        
        
        if(name.FindFirst(" ", charPos, 0))  
        {  
        if(!charPos)  
        {  
        GePrint("Exiting");  
         return TRUE;  
        }  
          
        name[*charPos] = '_';  
        }  
        
    

    The charPos pointer will ALWAYS return NULL! The really confusing thing is that the console will always print "Exiting" meaning that the FindFirst() is finding the " " in the name string. So the question is: Why is the LONG *Pos parameter not returning a correct pointer? As always any help on this is always much appreciated.
    Josh



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

    On 28/03/2007 at 14:28, xxxxxxxx wrote:

    You have only created a NULL pointer. You have to allocate a LONG variable and pass the pointer to FindFirst. This should work:

      
    LONG charPos = 0; //create a variable on the stack  
    String name("Cube Whatever");  
      
    if(name.FindFirst(" ", &charPos;, 0)) //pass the address (pointer) of charPos  
    {  
    name[charPos] = '_';  
    }  
    

    Alternatively you can also allocate a LONG on the heap with gNew, just make sure to de-allocate it with gDelete. Note always use Cinemas own allocation methods to ensure maximum platform compatibility.

    cheers,
    Matthias



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

    On 28/03/2007 at 14:44, xxxxxxxx wrote:

    Thanks for the quick reply. I assumed that the pointer would be filled by the FindFirst() which is why I initially set it to NULL. But this makes sense, thanks once again.
    Josh


Log in to reply