Update on char counter (vb.net)

Well my previous post spoke about a char counter. After posting it on a different blog several months ago I followed it with the below post.

Today I went to put it into a program and quickly realized some short comings. Hopefully this fixes them.

sFor previously could only be one character long. Well what if you want to search for an entire string. You need to divide the length by the length of the searching string. Also, If you don’t care about case since the sIn could be mixed case we need to lower that and then lower the sFor, instead of just lowering and upping the sFor. This in theory will slow it down since the string could be longer than lowering the sFor and sIn, but I cant think of a way around that.

Function cnt_occ(ByRef sIn As String, ByRef sFor As String, Optional ByVal casesensitive As Boolean = False) As Integer
If casesensitive Then
Return (sIn.Length – sIn.Replace(sFor, “”).Length) / sFor.Length
Else
Return (sIn.Length – sIn.ToLower.Replace(sFor.ToLower, “”).Length) / sFor.Length
End If
End Function

  1. March 22nd, 2017
    Trackback from : nicki minaj mixtape
Comments are closed.
%d bloggers like this: