fc 1,c++ & mysql program.

Markku Kolkka markkukolkka at kolumbus.fi
Tue Jun 22 12:46:36 UTC 2004


david kirjoitti viestissään (lähetysaika tiistai, 22. kesäkuuta 
2004 14:25):
> void replaceAll(string & src, const string & findstr, const
> string & replstr)
> {
> 			int found = src.find(findstr);
                        // let's be 64-bit safe:
                        size_type found = src.find(findstr); 
> 			while (found != string::npos)
> 			{
> 				src.replace(found, find.length(),
> replstr);
                                // I guess you meant this:
                                src.replace(found,
                                            findstr.length(),
                                            replstr
> 				found = src.find(findstr);
> 			}
> }

> void split (const string & s, char * delim, string dest[])
> {
> 			string temp = s;
> 			int count = 0;
> 			char *p;
> 			p = strtok(temp.begin(), delim);
                        /* the first parameter to strtok must be
                           a C string (char*), not a 
                           std::string::iterator */
                        char *s = new char[temp.length()+1];
                        strcpy(s, temp.c_str());
                        p = strtok(s, delim); 
> 			while(p != NULL)
> 			{
> 				dest[count] = p;
> 				count++;
> 				p = strtok(0, delim);
> 			}
> 			for(int temp=0;temp != count;temp++)
> 				dest[temp].erase(0,dest[temp].find("=")
> +1);
                        // cleanup
                        delete s[];
> }

-- 
	Markku Kolkka
	markku.kolkka at iki.fi





More information about the fedora-list mailing list