|
Dear Roger, Why not use CHECK opcode this way :- C ' ' CHECK String Pos 2 0 This checks for blank character from left and returns the position in the string where the blank character is not found. The Pos Numeric Field will contain the position of the first Non Blank from left . This can be used for a Substring from that position to the end of the field. regards, Abhishek > -----Original Message----- > From: Roger Pence [SMTP:rp@rogerpence.com] > Sent: Thursday, September 09, 1999 6:22 AM > To: MIDRANGE-L@midrange.com > Subject: Re: Testing for first non-blank character > > > Does anybody have a brilliant little piece of RPGIII code to test for > the > > first non-blank character in a right-justified (sorry, JDE stuff) > character > > field so that I can substring from that position to the end of the > field? > I > > really don't want to use a data structure and test each character if I > don't > > have to... I have my pride <g>. > > Many years ago, Julian Monypenny showed me this clever technique. It uses > two moves to continually shift off each left most position of the source > string. The key to the technique is to have a work field 1 byte shorter > than > the string you're parsing. Julian benchmarked this against several other > methods and this one was wayyyy faster. Sorry for the pseudo code, but > you'll get the idea. > > Const srcStrLen = 60 > srcStr LEN( srcStrLen ) > tgtStr LEN( srcStrLen - 1 ) > tstStr LEN( 1 ) > > for x = 1 to srcStrLen > * move leftmost char of source string to work value > MoveL srcStr to tstStr > * test it for blanks > if tstStr = *BLANK > do something > * if you choose to break out of the loop here, x = position of > first > blank character in source string > endif > * next two lines shift off current leading character of source string > movel srcStr tgtStr > move tgtStr srcStr > next x > > rp > > +--- > | This is the Midrange System Mailing List! > | To submit a new message, send your mail to MIDRANGE-L@midrange.com. > | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. > | To unsubscribe from this list send email to > MIDRANGE-L-UNSUB@midrange.com. > | Questions should be directed to the list owner/operator: > david@midrange.com > +--- +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.