How to resolve the algorithm Count occurrences of a substring step by step in the Eiffel programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count occurrences of a substring step by step in the Eiffel programming language

Table of Contents

Problem Statement

Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:

It should return an integer count. The matching should yield the highest number of non-overlapping matches. In general, this essentially means matching from left-to-right or right-to-left   (see proof on talk page).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Count occurrences of a substring step by step in the Eiffel programming language

Source code in the eiffel programming language

class
	APPLICATION
inherit
	ARGUMENTS
create
	make
feature {NONE} -- Initialization
	make
			-- Run application.
		do
			occurance := 0
			from
				index := 1
			until
				index > text.count
			loop
				temp := text.fuzzy_index(search_for, index, 0)
				if
					temp /= 0
				then
					index := temp + search_for.count
					occurance := occurance + 1
				else
					index := text.count + 1
				end
			end
			print(occurance)
		end

	index:INTEGER
	temp:INTEGER
	occurance:INTEGER
	text:STRING = "ababababab"
	search_for:STRING = "abab"
end


  

You may also check:How to resolve the algorithm Miller–Rabin primality test step by step in the Fortran programming language
You may also check:How to resolve the algorithm Playing cards step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Own digits power sum step by step in the Java programming language
You may also check:How to resolve the algorithm Non-decimal radices/Input step by step in the SparForte programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the Fermat programming language