I'm looking for a parallel function similar to convert.
My requirement is to change a matching input string (if found) to a output string defined.
convert does pretty much the same but for a single character and not for a string.
Any ideas or solutions are appreciated.
K-
Whats next to convert function
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Premium Member
- Posts: 301
- Joined: Thu Jul 14, 2005 10:27 am
- Location: Melbourne, Australia
- Contact:
... you'll find it <a href="viewtopic.php?t=106358">here</a>
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
A slightly different version here.. I would be happy if somebody can guide me on how to free the return pointer. DSGuru2B's method will not work because free is called after return.jhmckeever wrote:... you'll find it <a href="viewtopic.php?t=106358">here</a>
Code: Select all
#include <string>
using namespace std;
char *pxEreplace(char *Inp, char *Sub, char *Rep, int Occur, int Pos)
{
string inpString(Inp);
string subString(Sub);
string repString(Rep);
int iter, count = 0;
Pos = Pos<=1?1:Pos;
Occur = Occur <= 0?inpString.length():Occur;
for(iter = inpString.find(subString, Pos); iter != string::npos; iter = inpString.find(subString, iter))
{
count++;
inpString.replace(iter,subString.length(),repString);
iter++;
if(count == Occur ) break;
}
char * retvalue = new char[inpString.size()+1];
strcpy(retvalue,inpString.c_str());
inpString.~string();
subString.~string();
repString.~string();
return retvalue;
}
D
Nevermind the free after the return. You can take that out. Its presence has no meaning except that I had it there just for experimentation. The DSEngine will free the memory of the variable used in the return command.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.