Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Extracting a given number of characters from a string
Go
New
Search
Notify
Tools
Reply
  
Extracting a given number of characters from a string
 Login/Join
 
Silver Member
posted
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 Smiler
 
Posts: 31 | Registered: November 17, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
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.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.06OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6270 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
Denny,

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.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5682 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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 ...


GamP

- Using AS 8.2.01 on Windows 7 - IE11.
in Focus since 1988
 
Posts: 1960 | Location: Netherlands | Registered: September 25, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Also, you might use POSIT (check spelling) to find the period and calculate your start and end to use the substrn function.


Leah
 
Posts: 1317 | Location: Council Bluffs, IA | Registered: May 24, 2004Reply With QuoteReport This Post
Expert
posted Hide Post
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
with RJUST/SUBSTR
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!




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
 
Posts: 3811 | Location: Manhattan | Registered: October 28, 2003Reply With QuoteReport This Post
Gold member
posted Hide Post
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
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Reply With QuoteReport This Post
Expert
posted Hide Post
Charlz,

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.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5682 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
Gold member
posted Hide Post
Tony A,

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 !

Thanks !


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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!




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

 
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
You're welcome Frank, always glad to be of help.


GamP

- Using AS 8.2.01 on Windows 7 - IE11.
in Focus since 1988
 
Posts: 1960 | Location: Netherlands | Registered: September 25, 2007Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Extracting a given number of characters from a string

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.