Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.visual.basic    |    MS Visual Basic discussions, NOT dot-net    |    10,840 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 8,944 of 10,840    |
|    Rick Rothstein to All    |
|    Re: String function help    |
|    03 Nov 04 10:23:36    |
      From: rickNOSPAMnews@NOSPAMcomcast.net              > >> Is there a string function that returns the number of times       > >> string a occurs in string b?       > >       > >Not directly, but there is simple code to do that...       > >       > >OccurrenceCount = UBound(Split(StringB, StringA))       > >       > >There are optional argument to the Split, one of which will allow you       to       > >make the "search" case insensitive if you need that.       >       > Rick, that is disgraceful advice       > Physically splitting a String into an Array just to count instances of       > a substring is incredibly inefficient              If the Split function call is going to be used in a large loop, over and       over again, then yes, it would not be advisable (Split is definitely       slower than other options). However, counting the number of times one       string occurs inside of another is not something you normally do more       than once for a given string and sub-string (so I wouldn't characterize       using it as "incredibly inefficient" in this case). Given that, I think       a user would be hard pressed to see the time differential between using       the code I suggested and any other method one might offer (we are       talking a small amount of milli-seconds here).              Rick - MVP              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca