function cs = count_substring(str, substr)
%#codegen

    l_sub = length(substr);
    l_str = length(str);
    
    cs = 0;
    for i=1:(l_str-l_sub+1)
        if strcmp(str(i: i+l_sub-1), substr)
            cs = cs +1;
        end
        
    end

end