[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: Number of time a char is found in a string



David,
   You can code a procedure yourself... Here's an example that will
return the number of occurances of a given character in a string...
I'll assume the string name is $rec in tis example... #ctr is
returned... (Number of occurrances)...

..
..
  let $lf  = chr(10)
  do Number-Of-Chars($rec,$lf,#ctr)
..
..

!**********************************************************************
!*       Number of Characters in String                               *
!**********************************************************************

begin-procedure Number-Of-Chars($I_string, $I_char, :#O_ctr)

let #O_ctr   = -1
let #pos     =  0

while #pos    > 0
   or #O_ctr  < 0

  let #pos    = instr($I_String, $I_char, #pos + 1)
  let #O_ctr  = #O_ctr + 1

end-while

end-procedure

!**********************************************************************

Hope this solves your problem.    -Tony DeLia





David Dawes Stanley wrote:
>
> Does SQR have a string function to find the number of times a character is
> found in a string? I'm working with comment fields that are up to 2000
> chars. I need to find the total returns(linefeeds) so I can determine the
> page break. I need to assign #linefeeds the correct value.
>
> ie: if #current-line > #lines_per_param - #linefeeds
>        new-page
>      end-if
>         I looked in the manual and it didn't appear to have anything. Any input
> appreciated.
>
> David Dawes Stanley
> Lead Programmer Analysis/Web Master
> SUNY SICAS Center
> http://sicas.suny.edu/
> http://www.oneonta.edu/~stanley

--
Tony DeLia
AnswerThink Consulting Group
PeopleSoft Solutions Practice - Delphi Partners
tdelia@erols.com