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
Format string
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 209
- Joined: Fri Jan 09, 2004 1:14 pm
- Location: Toronto, Canada
- Contact:
Re: Format string
Try
YourInputString [1,3] : '-' : YourNewVal : YourInputString [2]
YourInputString [1,3] : '-' : YourNewVal : YourInputString [2]
Rob Wierdsma
Toronto, Canada
bartonbishop.com
Toronto, Canada
bartonbishop.com
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
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:
Remember you can also build a custom routine using "Case' statements for achieving the same.
Thanks,
Naveen.
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.
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
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
-
- Participant
- Posts: 221
- Joined: Fri Feb 17, 2006 3:38 am
- Location: India
- Contact:
Re: Format string
Hi,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
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
Parag Saundattikar
Certified for Infosphere DataStage v8.0
-
- Premium Member
- Posts: 209
- Joined: Fri Jan 09, 2004 1:14 pm
- Location: Toronto, Canada
- Contact:
Re: Format string
I think I'd stick with the KISS rule on this one.
Rob Wierdsma
Toronto, Canada
bartonbishop.com
Toronto, Canada
bartonbishop.com
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
Re: Format string
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
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
Try this:
in your routine.
Thanks,
Naveen.
Code: Select all
NewString = Ereplace(MyString, "-","-":MyString1:"-")
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
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE