Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Substring and position from reverse

Read-Only Read-Only Topic
Go
Search
Notify
Tools
Substring and position from reverse
 Login/Join
 
Platinum Member
posted
Hi ,
I have a field which is like
0110110011111001

I need to find the position of the second occurance of 1 from the end.
Is this possible..?


App Studio Version 8202
windows Platform
SQL Server 2008/2012
 
Posts: 183 | Location: TX | Registered: January 22, 2007Report This Post
Virtuoso
posted Hide Post
If the string is always the same length, you might create individual 1 character fields with edit, or possible using gettok or posit might help.


Leah
 
Posts: 1317 | Location: Council Bluffs, IA | Registered: May 24, 2004Report This Post
Virtuoso
posted Hide Post
There is no 1 step approach I think. Try:
DEFINE FILE CAR
NUM/A16='0110110011111001';
-* Remove trailing '0's
TRIM1/A16V= TRIMV('T',NUM,16,'0',1,'A16V');
-* Remove last character, which will be a '1'
TRIM2/A16V= SUBSTV(16,TRIM1,1,LENV(TRIM1,'I2')-1,'A16V');
-* Remove trailing '0's
TRIM3/A16V= TRIMV('T',TRIM2,16,'0',1,'A16V');
-* Length will be position of penultimate 1.
PLACE/I2=LENV(TRIM3,'I2');
END
TABLE FILE CAR
PRINT COUNTRY NUM TRIM1 TRIM2 TRIM3 PLACE
END

(Edit: Changed length 15 to 16 because, as Tony pointed out, I cannot count early in the morning!)

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Expert
posted Hide Post
Alan, shouldn't the lengths be 16 and not 15? Wink (early morning)

Getit,

I did think about using GETTOK and setting the delimiter to '0' especially as the GETTOK allows search from end using -1 for the last and -2 for the second to last etc. But in the string supplied the second to last would actually be '' as there are two 0s together. The second to last 1 would need -3 and that would return 11111 Frowner

So, depending upon your file type the only thing that I can think of that may help is the POSITION attribute within a MFD (mas). From the DS help files -

FILENAME = EXAMPLE3, SUFFIX = FIX,$
SEGNAME = ONE, SEGTYPE=S0,$
FIELDNAME = A1 ,ALIAS= ,USAGE = A14 ,ACTUAL = A14 ,$
FIELDNAME = QFIL ,ALIAS= ,USAGE = A32 ,ACTUAL = A32 ,$
FIELDNAME = A2 ,ALIAS= ,USAGE = I2 ,ACTUAL = I2 ,$
FIELDNAME = A3 ,ALIAS= ,USAGE = A10 ,ACTUAL = A10 ,$
FIELDNAME = A4 ,ALIAS= ,USAGE = A15 ,ACTUAL = A15 ,$
SEGNAME = TWO, SEGTYPE=S0, PARENT = ONE, POSITION = QFIL, OCCURS = 4 ,$
FIELDNAME = Q1 ,ALIAS= ,USAGE = D8 ,ACTUAL = D8 ,$

You can see that this is a flat file and the repeating values are in field QFIL.

I'm sure that Alan will now go and knock up an example Wink for his library of useful tips

Good luck

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: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Virtuoso
posted Hide Post
Here's another way to find the second to last occurance of the 1. The key to this techniaue is to reverse the string and then use POSIT to find the position of the second to last 1. This is probably not the best solution but it works.

DEFINE FILE CAR
ORGNUM/A16='0110110011111001';
REVNUM/A16=REVERSE(16,ORGNUM,'A16');
FSTONE/I2 =POSIT(REVNUM,16,'1',1,'I2');
NUMTWO/A16=SUBSTR(16,REVNUM,FSTONE+1,16,16-FSTONE,'A16');
SECONE/I2 =POSIT(NUMTWO,16,'1',1,'I2');
THEPOSITION/I2=(16-(FSTONE+SECONE))+1;
END
TABLE FILE CAR
PRINT ORGNUM REVNUM FSTONE NUMTWO SECONE
THEPOSITION AS 'The Second 1 is,Located at Position'
BY COUNTRY
WHERE RECORDLIMIT EQ 1
END


Thanks!

Mickey

FOCUS/WebFOCUS 1990 - 2011
 
Posts: 995 | Location: Gaithersburg, MD, USA | Registered: May 07, 2003Report This Post
Platinum Member
posted Hide Post
I came up with the exact solution as Alan Bs yesterday and it is working fine.
Mgrackin 's also is a good idea.

Thanks Guys!!


App Studio Version 8202
windows Platform
SQL Server 2008/2012
 
Posts: 183 | Location: TX | Registered: January 22, 2007Report This Post
Virtuoso
posted Hide Post
I did not test either of the solutions, but what if the original number has only one "1" pe "0000000010" or "010000000" or "1"....

You can test this by first converting the number from binary to decimal.
If the decimal number is 2^0 till 2^15 than the binary number only holds one "1" and the other tests can be passed.

Just a thought...




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, 2006Report This Post
Virtuoso
posted Hide Post
Frank,

The code I gave will return a PLACE value of 0, when the string contains only one '1'. The beauty of AnV fields. Smiler


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Substring and position from reverse

Copyright © 1996-2020 Information Builders