// This function counts the number of occurences of a given string within another string // - IF string is NOT found, it returns 0 // - otherwise it returns the number of occurences of the substring // - parameters: // 1. string: this is the search item // 2. string: this will be searched for the first string // 3. is overalpping of search results allowed: // - default: FALSE (NO) // 4. START position: default = begining of string (=1) // 5. END position: default = LEN(string) void ScInterpreter::ScFindCount() { BYTE nParamCount = GetByte(); if ( MustHaveParamCount( nParamCount, 2, 3, 4, 5 ) ) { double nCount = 0; // Count the number of occurences of the substring double fBegin; // START of String double fEnd; // END of String double fLen; // Length of Search String BOOL nSearchOverlap; // Overalpping search String sStr; // Search within this string String sSearch; // This is searched fBegin = 1.0; nSearchOverlap = false; // NO Overlapping strings allowed if (nParamCount == 5) { fEnd = GetDouble(); fBegin = GetDouble(); nSearchOverlap = GetBool(); sStr = GetString(); if( fEnd > (double) sStr.Len() ) fEnd = sStr.Len(); } else if (nParamCount == 4) { fBegin = GetDouble(); nSearchOverlap = GetBool(); sStr = GetString(); fEnd = (double) sStr.Len(); } else if (nParamCount == 3) { nSearchOverlap = GetBool(); sStr = GetString(); fEnd = (double) sStr.Len(); } else { sStr = GetString(); fEnd = (double) sStr.Len(); } if( fBegin < 1.0 ) fBegin = 1.0; sSearch = GetString(); // Get String that will be searched fLen = sSearch.Len(); if( fLen = 0.0 ) // IF search string is EMPTY => ERROR SetNoValue(); else if( fBegin > fEnd ) PushDouble((double) 0.0); else if( nSearchOverlap == true ) { for(xub_StrLen nPos = fBegin - 1 ; nPos < fEnd; ) { nPos = sStr.Search( sSearch, nPos ); if (nPos != STRING_NOTFOUND) { nPos += fLen; nCount++; } } PushDouble(nCount); } else { // alternatively: use "fLen = 1" in previous "else if" block for(xub_StrLen nPos = fBegin - 1 ; nPos < fEnd; ) { nPos = sStr.Search( sSearch, nPos ); if (nPos != STRING_NOTFOUND) { nPos ++; nCount++; } } PushDouble(nCount); } } }