String function: counting substring
Is there an intrinsic function to count how many times a substring appears in a given string?
|
Not that I am aware of. I guess you could "simulate" this by using pos() function, loop and keep cutting the string down in size using mid() until pos() returned -1.
Have to say I think that would be "really" high CPU as HL does not do great with string calculations... |
That is what I was afraid of.
I am looking at if there is a feasible way to implement something like Boyer-Moore (which is O(n) and I think is the standard for regex type searches) or other fast search algorithms using the scripting language. The one saving grace is that in HL we typically do not have long strings to search through. |
See if you can resolve this by assigning tags to represent whatever you're testing for, and then counting the tags.
|
I don't think tag would work here. I am looking to parse a string with some delimiter between items and convert that into a properly formatted list ending with the proper final conjunction with the Oxford comma if there are more than two delimiters.
I got something working but I am trying to optimize it. I will post the code when I am mostly happy with it. |
Ok, I did find I way to do it intrinsically, but it seemed to run slow as well as not be able to handle the cases where we were searching for a string made up of repeated characters very well. So... I went with a workaround requires the input of the number of things that make up the list instead of figuring it out from the string itself since these strings will be generated with things like tagname[], or foreach loops.
Here is what I have for parsing the list Code:
~ this procedure is used to generate a formatted list with and/or at the end Code:
~ this procedure counts now many times a given substring appears in a given string |
All times are GMT -8. The time now is 07:22 AM. |
Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.