Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating a specific character in a string between dates

Status
Not open for further replies.

adnil

Technical User
Oct 29, 2003
50
GB
Hi

CRY XI and DB.

We have a string that consists of X, A and H. Each string has it's own start and end date and the length of the string varies. For example:

XAAHHAAAAAHHHHHHHXAAAA

How can I calculate the number of As in a defined start and end dates? So if the above string has a start date of 3 Jan'14 and I want the count the number of As between 1/1/14 to 15/1/14, the result will be 7.

How can I achieve this please?

Thank you.
 
To count the number of As in the string, you might try something like this:

Length({MyTable.stringField}) - Length(Replace({MyTable.stringField}, "A", "")

or

Length(Replace(Replace({MyTable.stringField},"H",""), "X", ""))

You would then filter the report based on the dates and sum this formula to get you the total number of As in the data set.

-Dell

DecisionFirst Technologies - Seven-time SAP BusinessObjects Solution Partner of the Year
 
Here is a function I came up with that counts the occurrences of a character in a string:

Function (STRINGVAR FIND, STRINGVAR RAW)
// FUNCTION CHARCNT
// INPUT A search character and a string (or field)
// OUTPUT how many times the search character appears in the string
local numbervar I :=1;
local numbervar gotit := 0 ;
while I <= len(RAW)
do (if (Mid(RAW,I,1) = FIND)
then gotit := gotit+1 else gotit := gotit;
I:= I+1) ;
local numbervar gotit
 
Hi Dell and Charliy, thank you for your suggestions. I have got it sorted now.

Lin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top