I have a 80 character field that I need to extract the last 15 positions (minus the peroid). For example, within - "xwzo abcde ghig - nbnbc uucucb 12345678-0728." I need to extract "12345678-0728" only. What can be entered into this field is dynamic but what is a constant is I need the last 13 positions minus the period. I looked at the "GETTOK" function but it didn't work. Any Ideas? Thanks
If the position within the 80-character field is fixed, all you need is SUBSTR, with appropriate (integer) arguments for start and end position and length of the portion to extract.
If location varies, and you want the tail end of the text, use ARGLEN to locate the end, and fashion expresions for the start/end column arguments accordingly.
- Jack Gross
WF through 8.1.05
As Jack says, ARGLEN to find the length of the text if it isn't fixed and 80 chars.
You could also use RJUST and SUBSTR or REVERSE / SUBSTR or EDIT / REVERSE.
Check out the WebFOCUS Functions documentation, there is quite a few string fucntions available.
I would go for the REVERSE function and I suggested a method in this topic - "Function for getting right two characters" last year, but there are earlier suggestions of a similar process from previous years.
Alternatively, you could solve this in your master file, provided the part you're interested in is always the last so many positions.
The way to do this is to make this 80 character field a group field, and then create three fields in that group field: a field that hold the first 65 positions, next a field for the 14 you want, and last a field for the period.
That way, just referencing the field will give you the portion you want, in stead of having to resort to functions to do the same thing.
Mind you, this is only going to work if positions are fixed.
Hope this helps ...
Also, you might use POSIT (check spelling) to find the period and calculate your start and end to use the substrn function.
No different from what everyone else has already said, i'ld go REVERSE/SUBSTRing/REVERSE
maybe with a POSIT before the SUBSTR, just to be sure.
i think i remember having ageda last year
for some reason, the RJUST just wouldn't do what i expected it to, i don't remember why.
but the REVERSE was the bomb!
I'm thinking maybe the "REVERSE" or "RJUST" functions may not trim trailing spaces ?
That would make the "last" characters NOT be what you had expected, so "TRIM" the string first ?
I like the idea of re-defining the field with overlaying sub-fields, IFF the SUBSTR you want is fixed.
It also saves a lot of processing time (i.e.: fewer function calls for all those SUBSTR, RJUST, POSIT, etc.)
I may post another separate request for info on a way to re-FIELD a records (is that called a "sub-mask" ?)
Thanks for a wealth of information from everyone !
WF 7.6.4 & 5.3
If you read the link I posted above and also the inference by Waz, you will see that ARGLEN is used to obtain the "real" length of the incoming data so the string that is reversed is stripped of trailing blanks first. That way you are controling what you achieve.
Yes, although it wasn't clear if the ARGLEN automatically TRIMmed the string, and I was trying to avoid all that processing needed for multiple function calls.
Thanks for the link to your previous post, which answered this, ++ PLUS ++ answered a question about functions I was going to ask, and now I don't have to !
WF 7.6.4 & 5.3
Denny seems to be overwhelmed by all the answers. I hope one of the answers solved his problem.
The answer GamP has given is for me an interesting one. I'm going to use it in one of my masters. Thx Gerard!
You're welcome Frank, always glad to be of help.
|Powered by Social Strata|