Extracting a Part from the given String
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 107
- Joined: Wed Sep 29, 2004 10:15 am
Hi ameyvaidya
Thanks for your response
The Routine works fine but it is not Full filling my requirement
ex1:
My String : ANSY, 3/4" SQ. DR., P/N 251-A626A,
Routine Output : P/N 251
My Desired Output has to be : P/N 251-A626A
Ex 2:
My String : BE PON AY, P/N 436A90-A602, FOR
Routine Output : P/N 436
My Desired Output has to be : P/N 436A90-A602
Can you guide me what are the necessary changes i had to do with the Code .
Thanks in Advance
RK
Thanks for your response
The Routine works fine but it is not Full filling my requirement
ex1:
My String : ANSY, 3/4" SQ. DR., P/N 251-A626A,
Routine Output : P/N 251
My Desired Output has to be : P/N 251-A626A
Ex 2:
My String : BE PON AY, P/N 436A90-A602, FOR
Routine Output : P/N 436
My Desired Output has to be : P/N 436A90-A602
Can you guide me what are the necessary changes i had to do with the Code .
Thanks in Advance
RK
-
- Charter Member
- Posts: 166
- Joined: Wed Mar 16, 2005 6:52 am
- Location: Mumbai, India
This line is the Key:
What i am doing here is checking for a pure numeric part number.
If the Part number can also have "-" then add
Add more conditions to this line to test for more cases. Everything else signifies the end of the part number.
Thats all
Code: Select all
IF NUM(InString[PnEndTester,1]) AND InString[PnEndTester,1]<>" " THEN
If the Part number can also have "-" then add
Code: Select all
AND InString[PnEndTester,1]="-"
Thats all
Amey Vaidya<i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
Hi,rkdatastage wrote:Hi ameyvaidya
Thanks for your response
The Routine works fine but it is not Full filling my requirement
ex1:
My String : ANSY, 3/4" SQ. DR., P/N 251-A626A,
Routine Output : P/N 251
My Desired Output has to be : P/N 251-A626A
Ex 2:
My String : BE PON AY, P/N 436A90-A602, FOR
Routine Output : P/N 436
My Desired Output has to be : P/N 436A90-A602
Can you guide me what are the necessary changes i had to do with the Code .
Thanks in Advance
RK
Try adding this to ameyvaidya code . This one will just extract the P/N bit
Total_length=Len(InString)
PnStart=INDEX(InString,"P/N",1)
Start=(Length1-PnStart)+1
Pnbefore=Field(Right(InString, Start),",",1)
Ans=Pnbefore
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Actually if you look at my routine, its fairly simple. Its not working because its not complete. You need an 'Ans' line. I left that upto you so that you can decide what delimiter should come between 'Part' and 'RestOfData'.
I delimited the two parts with a pipe.
In the transformer you can use a Field() function to get 'Part' which is before the Pipe and 'RestOfData' which is after the Pipe.
Code: Select all
Desc=TRIM(Arg1)
RestOfData=''
Part=''
EndForLoop=LEN(Desc)
FOR n = 1 TO EndForLoop
IF Desc[n,4] = 'P/N '
THEN
Part=Field(Desc[n,EndForLoop-n+1],1,2)
RestOfData=Desc[1,n-1]:Desc[n+Len(Part),EndForLoop-Len(Part)]
END
NEXT n
Ans=Part:"|":RestOfData
In the transformer you can use a Field() function to get 'Part' which is before the Pipe and 'RestOfData' which is after the Pipe.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.