Hi,
I would like to extract a string of data from a name. The position of the string varies in the name and the name has a variable number of sub-strings within it. An example is shown below:
(GPN) CI-4/E7/DH-1 15S-40 L1807
DEO (GPN) JD CI-4/E7/DH-1 5S-40 L1807
(GPN) JD CI-4/E7/DH-1 40 L1807
I am interested in two parts: a string which contains the letter S (so in the examples, 15S-40 & 5S-40) AND if w is not present, I am interested in the numeric value.
Is it possible to extract this using standard formula functions?
Any help would be great.
Thanks,
Dipesh
You haven't provided an example of something with a W in it so that is untested. I think this will solve your problems:
YourList = {"(GPN) CI-4/E7/DH-1 15S-40 L1807", "DEO (GPN) JD CI-4/E7/DH-1 5S-40 L1807", "(GPN) JD CI-4/E7/DH-1 40 L1807"};
Part1 = Part2 = {};
For(i=1,i<=N items(YourList),i++,
SubWords = Words(YourList[i], " ");
For(k=1,k<=N Items(SubWords),k++,
If(contains(SubWords[k],"S")>0,
Part1[i] = SubWords[k];
k=N Items(SubWords)+1;
)
);
);
For(i=1,i<=N items(Part1),i++,
If(contains(part1[i],"W")==0,
Part2[i] = right(part1[i],2);
)
);
It appears that the component you want to strip off is the second to the last grouping. If that is the case, then the code below will do that. The Word() function is a very powerful function. It's documentation can be found in either the Scripting Guide or the Scripting Index
Help==>Books==>Scripting Guide
Help==>Scripting Index==>Word
Names Default To Here( 1 );
dt = New Table( "test",
New Column( "String",
character,
values(
{"(GPN) CI-4/E7/DH-1 15S-40 L1807", "DEO (GPN) JD CI-4/E7/DH-1 5S-40 L1807",
"(GPN) JD CI-4/E7/DH-1 40 L1807"}
)
)
);
dt << New Column( "Value", character, formula( Word( -2, :String, " " ) ) );
Using a Regular Expression you can match a 'space' followed by some characters until you hit an 'S-' then more characters until you hit the next 'space'
PAT = "(GPN) CI-4/E7/DH-1 15S-40 L1807";
x = regex(PAT,"\S+(?=S-).* ");
show(x);
You haven't provided an example of something with a W in it so that is untested. I think this will solve your problems:
YourList = {"(GPN) CI-4/E7/DH-1 15S-40 L1807", "DEO (GPN) JD CI-4/E7/DH-1 5S-40 L1807", "(GPN) JD CI-4/E7/DH-1 40 L1807"};
Part1 = Part2 = {};
For(i=1,i<=N items(YourList),i++,
SubWords = Words(YourList[i], " ");
For(k=1,k<=N Items(SubWords),k++,
If(contains(SubWords[k],"S")>0,
Part1[i] = SubWords[k];
k=N Items(SubWords)+1;
)
);
);
For(i=1,i<=N items(Part1),i++,
If(contains(part1[i],"W")==0,
Part2[i] = right(part1[i],2);
)
);