Results 1 to 5 of 5

Thread: Split Function

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734

    Split Function

    Is there a split function in some of the more common libraries or would I have to write my own, I need something with the power of the vb split function. Thanks in advance.

  2. #2
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    Single-char splitter.

    Code:
    TCHAR** VirtualSplitString(TCHAR* pString, TCHAR sep, int& uBound)
    {
        unsigned long s = 0; unsigned long i = 0;
        TCHAR** pArray = (TCHAR**)calloc(strlen(pString), sizeof(TCHAR*));
    	
        //allocate empty storage
        
        //the first array
        pArray[0] = (TCHAR*)calloc(1024, sizeof(TCHAR));
    
        //separate an array...
        while(*pString)
        {
            //go through the string, find position
            if(*pString == sep)
            {    
                i++;
                s = 0; //current position
                //allocate space for new input
                pArray[i] = (TCHAR*)calloc(1024, sizeof(TCHAR));
            }
            else
            {
                //get the current character and set it
                pArray[i][s] = *pString;
    
                //increase character position
                s++;
            }
    
            //increase string position
            pString++;
    
        }
        
        uBound = ++i;
    
        //return the pArray data type
        return pArray;
    };
    
    //Frees a buffer
    void VirtualFreeHuge(char** pString, int uBound)
    {
    	//free each of the items
    	for(int i = 0; i <= uBound; i++)
    		free(pString[i]);
    
    	//free the item itself
    	free(pString);
    };
    VS.NET 2003

    Need to email me?

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Making good use of STL:
    http://www.vbforums.com/showthread.p...hreadid=227148
    all the way down.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    I tried your method in borland turbo compiler but it didnt work corned, I have vc 6.0 but have to use borland cause its what is at school =(

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    k got it to work =/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width