Page 1 of 1

Format string

Posted: Tue Feb 28, 2006 2:24 pm
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

Re: Format string

Posted: Tue Feb 28, 2006 2:41 pm
by rwierdsm
Try

YourInputString [1,3] : '-' : YourNewVal : YourInputString [2]

Posted: Wed Mar 01, 2006 8:32 am
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.

Re: Format string

Posted: Wed Mar 01, 2006 10:09 am
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.

Re: Format string

Posted: Wed Mar 01, 2006 11:50 am
by rwierdsm
:shock:

I think I'd stick with the KISS rule on this one.

Posted: Wed Mar 01, 2006 11:53 am
by I_Server_Whale
I think the logic suggested by parag is an over-overkill. Image

Thanks,
Naveen.

Re: Format string

Posted: Wed Mar 01, 2006 12:04 pm
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

Posted: Wed Mar 01, 2006 12:17 pm
by I_Server_Whale
Try this:

Code: Select all



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

 
in your routine.

Thanks,
Naveen.