Convert double character into single

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
dsquest
Participant
Posts: 6
Joined: Wed Mar 27, 2013 1:24 pm

Convert double character into single

Post by dsquest »

Hello,

This might have been discussed already. But I couldn't find anything close to my need.

I have the following.

Code: Select all

"|||abc|||def|hg"
I wanted it to be converted into

Code: Select all

"abc|def|hg"
I think I can remove the leading and trailing Pipes using Trim with 'B".

I have remove the duplicate intermediate pipes and replace into one.
FYI: Covert('||','|',input) isn't working.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If there are no space characters in your data (as per your example) you could convert the pipe characters to space characters, use a simple Trim() function (only one argument), then convert the space characters back to pipe characters.

Code: Select all

Convert(" ", "|", Trim(Convert("|",  " ",  InLink.TheString)))
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Code: Select all

TRIM("|||abc|||def|hg","|","R")
will do what you want.
chandra.shekhar@tcs.com
Premium Member
Premium Member
Posts: 353
Joined: Mon Jan 17, 2011 5:03 am
Location: Mumbai, India

Post by chandra.shekhar@tcs.com »

Ray, I must say that your solution is fantastic. :D
Last edited by chandra.shekhar@tcs.com on Mon Oct 07, 2013 12:36 am, edited 1 time in total.
Thanx and Regards,
ETL User
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

Ray,

Why do we need two converts, I believe trim with R should do the work. also suggested by Arnd.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
dsquest
Participant
Posts: 6
Joined: Wed Mar 27, 2013 1:24 pm

Post by dsquest »

Thanks AndrW! It worked!.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I'd forgotten the "R" option for Trim(). It's not an option I use very often.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply