on 05-26-2010 2:06 PM
I have text field data that looks like this:
RE-WORKX10/ZSB/Q2/ZONS/Q2/ZPM/Q7/
I am trying to pull the number after the X out up to /
Any suggestions
tx
Shirley
Try this...
Mid({TableName.StringField}, Instr({TableName.StringField},'X')+1,
(InStr({TableName.StringField},'/') - InStr({TableName.StringField},'X') -1))
HTH,
Jason
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
X isn't a variable. It's being used as a marker to indicate where you want to extracting text out of your string...
The supplied formula uses the Mid function to pull a section of text out of a string
Mid({your string field here}, start position, length of text to extract)
The 1st InStr function is used to find the 1st "X" in the string. The "+1" moves the pointer over 1 character, so that the X itself is not included.
Instr({TableName.StringField},'X')+1
The last part of the formula...
(InStr({TableName.StringField},'/') - InStr({TableName.StringField},'X') -1)
counts the number of characters between the 1st "X" and the 1st "/"... Thus supplying the Mid function the correct number of characters to extract.
So, based on the example to provided, the posted formula will return a value of 10.
Hi Jason,
I'm getting an error "String Length is less than 0 or not an integer" I have added the
if Instr({@Desc- Lower Case},'x')< 1 THEN '' to the original formula you supplied however I'm still getting the error.
The Formula giving the ERROR:
if Instr({@Desc- Lower Case},'x')< 1 THEN '' else
if (Instr({@Desc- Lower Case},'x')+1)IN [1 TO 9] THEN
Mid ({@Desc- Lower Case}, Instr({@Desc- Lower Case},'x')+1,
(InStr({@Desc- Lower Case},'/') - InStr({@Desc- Lower Case},'x') -1))
Data field examples:
fixed LB WO 0006254
Fixed sc/x5/zsb/q2/u5/w3
split/solder
x2/zpwv/q5/r8
I believe if I could narrow the field selection down to those records that have a number from 1 to 9 following the X I could create some consistency in the field? The above formula was the only thing I could come up with, but I am stll getting an error starting with Mid.
Any help would be greatly appreciated!!!!!
That work Sanjay. Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Getting error from prior formula
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
May I suggest an alternate formula which splits the string into pieces based on the existence of '/' and then evaluates each piece to see if 'x' exists and if the next character is numeric then display the text next to 'x' else blank.
For example:
// X is the string field
stringvar array a := split(x,'/');
stringvar z := '';
numbervar i;
for i := 1 to count(split(x,'/')) do
(
if instr(a<i>,'x') > 0 and a<i>[instr(a<i>,'x')+1] in '0' to '9' then
(
z := z & a<i>[instr(a<i>,'x')+1 to length(a<i>)];
exit for;
));
z;
If the data string happens to be a2/zpwv/q5/r8/x123x5 then it will return 123x5. Also, once it finds a matching condition it will quit and will not process the string further, if you want it to continue processing, just comment out the EXIT FOR statement.
For example, if the string is x2/a2/zpwv/q5/r8/x123x5 the result will be 2.
Edited by: Sanjay Kodidine on Jun 1, 2010 2:25 PM
Thank you for the input, I'm learning but not enough to find the error in this formula. I am getting a bracket error at the second " instr(ai],'x')" .
What does the [ bracket represent?
Will I need to create individual formulas for each split or does this formula evaluate all splits and return only the one with the number next to it?
// X is the string field
stringvar array a := split({@Des-Data Extraction},'/');
stringvar z := '';
numbervar i;
for i := 1 to count(split({@Des-Data Extraction},'/')) do
(
if instr(a<i>,'x') > 0 and a<i>[instr(ai],'x')+1 in '0' to '9' then
(
z := z & a<i>[instr(a<i>,'x')+1 to length(ai]);
exit for;
));
z;
Shirley
Shirley:
Just copy the following as is into a formula and run it. I do not get any errors when I run my original formula. The error comes into play when you substitute X with {@Des-Data Extraction} in some places only.
evaluateafter({@Des-Data Extraction});
stringvar x := {@Des-Data Extraction};
stringvar array a := split(x,'/');
stringvar z := '';
numbervar i;
for i := 1 to count(split(x,'/')) do
(
if instr(a<i>,'x') > 0 and a<i>[instr(a<i>,'x')+1] in '0' to '9' then
(
z := z & a<i>[instr(a<i>,'x')+1 to length(a<i>)];
exit for;
));
z;
This formula will evaluate all splits and return only the one with the number next to it (if any).
Edited by: Sanjay Kodidine on Jun 2, 2010 7:56 AM
If you have copied the formula exactly as is and not made any changes, then I am not sure why it is giving errors, unless CR 10.5 cannot handle array manipulation. I ran the formula in CR 2008, CR XI R1 and CR XI R2 and it works just fine without any errors. I have no way of testing it in CR 10.5.
Can anyone else confirm the limitation of CR 10.5?
If that is the case, then we are back to square one. Let me see if I can re-work the original formula, unless someone beats me to it
Sanjay,
I have a working formula that pulls the number to the right of the x already. The problem is users are enter comments before the x such as words like fixed.
fixed sc x3/zsb/q1/u5
All I really need is something that will look for the first instance of an X with a Number after it and then return everything to the right of it. I just want to eliminate anything before that X3.
x3/zsb/q1/u5
OK here is a modified formula without any arrays. It has limitations in that it will process up to two 'x's being present in the string. For example: fixed sc x1113/zsb/q1/u5 will work fine or one without any X but if the string has 3 Xs then it wont work unless the ELSE part is modified.
stringvar s := {@Des-Data Extraction};
if instr(s,'x') > 0 and mid(s,instr(s,'x')+1,1) in '0' to '9' then
Mid (s, Instr(s,'x')+1,(InStr(s,'/') - InStr(s,'x') -1))
else
(
s := replace(s,'x','.',1,1);
if instr(s,'x') > 0 and mid(s,instr(s,'x')+1,1) in '0' to '9' then
Mid (s, Instr(s,'x')+1,(InStr(s,'/') - InStr(s,'x') -1));
);
Edited by: Sanjay Kodidine on Jun 3, 2010 4:00 PM
stringvar s := {@Des-Data Extraction};
//
if instr(s,'x') > 0 and mid(s,instr(s,'x')+1,1) in '0' to '9'
and instr(mid(s,instr(s,'x')+1,length(s)),'/') <= 0 then
Mid (s, Instr(s,'x')+1,length(s))
else
if instr(s,'x') > 0 and mid(s,instr(s,'x')+1,1) in '0' to '9' then
Mid (s, Instr(s,'x')+1,(InStr(mid(s,instr(s,'x')+1,length(s)),'/')-1))
else
(
s := replace(s,'x','.',1,1);
if instr(s,'x') > 0 and mid(s,instr(s,'x')+1,1) in '0' to '9' then
Mid (s, Instr(s,'x')+1,(InStr(mid(s,instr(s,'x')+1,length(s)),'/')-1))
);
PS: If the formula fails, please provide the field value (displayed on the left hand side in the formula workshop) so that it is easier to debug rather than having to "figure out" what might have caused the problem.
try this
left ({USR_CR_BSA_ALERTS;1.A_DESC}, InStr({USR_CR_BSA_ALERTS;1.A_DESC}, "' "))
it should return what ever is to the left of what is in the ""
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.