Advertisement
3_2004-2005 String Manipulation #131452

A CountChar - Better than looping through a string!!!

It used to be, when I wanted to count the number of times a charector appeared in a string, I would loop through the string letter by letter and keep a count. I have replace my old methodolgies with this one, which also allows you to search for substrings (more than 1-digit long)

AI

Resumen de IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Código fuente
original-source
<BR><BR>Public Function CountChar(vText as String, vChar as String, Optional IgnoreCase as Boolean) as Integer<BR>
&nbsp;&nbsp;If IgnoreCase Then <BR>
&nbsp;&nbsp;&nbsp;&nbsp;vText = LCase$(vText) <BR>
&nbsp;&nbsp;&nbsp;&nbsp;vChar = LCase$(vChar) <BR> &nbsp;&nbsp;End If <BR>
&nbsp;&nbsp;Dim L as Integer <BR>
&nbsp;&nbsp;L = Len(vText) <BR><BR>
&nbsp;&nbsp;vText = Replace$(vText, vChar, "") <BR>
&nbsp;&nbsp;CountChar = (L - Len(vText)) / Len(vChar) <BR>
End Function
Comentarios originales (3)
Recuperado de Wayback Machine