Format string

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sainath
Premium Member
Premium Member
Posts: 138
Joined: Fri Nov 19, 2004 3:57 pm

Format string

Post by sainath »

Hi
I have a input string.
ABC-1
DEF-2 etc.

I have to insert 3 letter code in middle like
ABC-OPR-1
DEF-NOP-2.
which function i have to use.
THKS
rwierdsm
Premium Member
Premium Member
Posts: 209
Joined: Fri Jan 09, 2004 1:14 pm
Location: Toronto, Canada
Contact:

Re: Format string

Post by rwierdsm »

Try

YourInputString [1,3] : '-' : YourNewVal : YourInputString [2]
Rob Wierdsma
Toronto, Canada
bartonbishop.com
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi Sainath,

You can also use the Ereplace Function to achieve this.

Assuming that you have more than the two cases that you have posted.

You could write the code in the lines as below:

Code: Select all


If InputString[1,3] = 'ABC'

Then  Ereplace(InputString, "-", "-OPR-")

Else if InputString[1,3] = 'DEF'

Then  Ereplace(InputString, "-", "-NOP-")

Else if InputString[1,3] = 'GHI'

Then Ereplace(InputString, "-", "-PQR-")

                     |
                     |
                     |
        And so on for as many cases as you have.

Remember you can also build a custom routine using "Case' statements for achieving the same.

Thanks,
Naveen.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Re: Format string

Post by parag.s.27 »

sainath wrote:Hi
I have a input string.
ABC-1
DEF-2 etc.

I have to insert 3 letter code in middle like
ABC-OPR-1
DEF-NOP-2.
which function i have to use.
THKS
Hi,

You can simply write a routine in which you can find the exact place of "-" and replace it with desired value.

The function you can use is INDEXOF().

The code is

First in the Argument tab of routine workspace define 2 arguments: -
FieldData & SpecialChar

Then in the code section write this code: -

VarTrim=Trim(FieldData);
VarNew='';
VarSpec=SpecialChar;
VarIndex=Index(VarTrim,VarSpec,1);
VarCount=0;

If VarIndex <> 0 then
Loop While VarCount <= Len(VarTrim);
VarCount = VarCount + 1;
If VarIndex <> 0 then VarNew = (VarTrim[0,VarIndex-1]:'-OPR-':VarTrim[VarIndex+1,Len(VarTrim)]) else VarNew = VarTrim;
VarTrim = VarNew;
VarIndex = Index(VarTrim,VarSpec,1);
Repeat
End
Else VarTrim=Trim(FieldData);
Ans=VarTrim;

This routine will replace all special characters with any desired value u want. Remember to feed the field value and the special char as an input to the routine.
Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
rwierdsm
Premium Member
Premium Member
Posts: 209
Joined: Fri Jan 09, 2004 1:14 pm
Location: Toronto, Canada
Contact:

Re: Format string

Post by rwierdsm »

:shock:

I think I'd stick with the KISS rule on this one.
Rob Wierdsma
Toronto, Canada
bartonbishop.com
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

I think the logic suggested by parag is an over-overkill. Image

Thanks,
Naveen.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
sainath
Premium Member
Premium Member
Posts: 138
Joined: Fri Nov 19, 2004 3:57 pm

Re: Format string

Post by sainath »

sainath wrote:Hi
I have a input string.
ABC-1
DEF-2 etc.

I have to insert 3 letter code in middle like
ABC-OPR-1
DEF-NOP-2.
which function i have to use.




Hi
Thanks for your reply.

Based on if condition i have to insert either OPR or NOP in middle .

i wrote routine
MyString = Input_Data.GRADE_NAME
MyString1 = LkupJobDefination.SEGMENT4

NewString = Ereplace(MyString, "-","-"MyString1"-")

Ans = NewString

I am getting ABCNOP1 BUT I WANT ABC-NOP-1.



THKS
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Try this:

Code: Select all



NewString = Ereplace(MyString, "-","-":MyString1:"-") 

 
in your routine.

Thanks,
Naveen.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
Post Reply