Search code examples
c#arraysstringalgorithmprefix

Having trouble with similar key prefixes, ie. "Tag1" is called instead of "Tag10" despite both existing


I have an array of valid prefixes, and let's say we have "tag1" and "tag10".
If I am removing prefixes so that "tag1Date" and "tag1Name" become just "Date" and "Name", the issue is that I end up also getting "0Date" and "0Name".
I've though about checking the character after "tag1" to see if it's a number or not, if so it must be a separate tag, but can't get it working.
Can't show code unfortunately because it's proprietary. All help welcome!


Solution

  • Order your tags array in decending order then remove the prefix's.

    For example Array should be ["tag10", "tag1"]

    Then you remove tag10 first then tag1