[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 didn't say what operating system you are on, but if you're on Unix then this may help you.  The CALL SYSTEM USING command can't normally be used to retrieve information from Unix, but because you are after a number we can be tricky and use the return-status of the command to get our answer.  The Unix 'wc' command counts the number of lines/words/characters in a string or file.  The -l flag only returns the lines.  As you are interested in counting the linefeeds this should give you what you want.  By imbedding our call within a Unix 'exit' statement the results of the call will be returned as the status.

    eg    call system using 'exit `echo "' || $comments || '" | wc -l`' #linefeeds

The different quotes used may need clarification.  The ' character delimits the literal command.  The " character delimits the text that would be interpreted from the $comments field (this is just to play it safe as it contains imbedded linefeeds).  The ` character delimits the subcommand that is executed first - thus the subcommand might return 25 so the outer command would become 'exit 25' and #linefeeds (the return status) would be set to 25.

I haven't tried any of this, but I'd be interested to know if it works.  Tony's solution would most likely be more efficient but this is something quick and dirty that should do the job.

Wayne Ivory
Information Services
Westralian Sands Limited


>>> David Dawes Stanley <stanledd@SNYONEVA.CC.ONEONTA.EDU> 22/10/98 4:04:57 pm >>>
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