Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
07-08-2009, 07:25 AM #1
- Join Date
- Feb 2009
- Thanked 0 Times in 0 Posts
[C/CPP] Can this be done? Replacing words..
I have an ASCII file input.sql which contains a database dump. I want that all the 5 lettered words that fall between a left parentheses i.e. ( and a comma i.e. , be replaced by the string (NULL,
I did that with ease in PHP, but in c/cpp, it seems difficult.
Here's the PHP code:
$blah1=preg_replace('/\(.....,/', '(NULL,', $blah);
07-13-2009, 04:08 PM #2
It's easily done in C++ with boost::regex_replace
It's also rather easily done in either language using a state machine. Just loop the characters and start counting at each left paren. When the next comma comes up (or the count gets too high) replace if the count indicates the pattern has been matched, otherwise reset and carry on looking for the next paren.
Last edited by ralph l mayo; 07-13-2009 at 07:27 PM.