Whats next to convert function

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
kommven
Charter Member
Charter Member
Posts: 125
Joined: Mon Jul 12, 2004 12:37 pm

Whats next to convert function

Post by kommven »

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-
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Search the forum. DSGuru2B published a parallel function that mimics the Ereplace() function from server jobs.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

... 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>
iDomz
Participant
Posts: 81
Joined: Wed Jul 25, 2007 5:25 am
Location: London

Post by iDomz »

jhmckeever wrote:... you'll find it <a href="viewtopic.php?t=106358">here</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.

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;
}  
Cheers,
D
kommven
Charter Member
Charter Member
Posts: 125
Joined: Mon Jul 12, 2004 12:37 pm

Post by kommven »

I will try this out and update.
Thanks,
K-
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

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.
Post Reply