LabVIEW Idea Exchange

Showing results for 
Search instead for 
Did you mean: 

Extend String Search Functions with "Last Occurence" and "Max Offset"

Status: New

I would like to be able to

  1. find the last occurence (=rfind in C++/python)
  2. Search a match between position 10 and 20

So I propose to extend the search functions with

    1. an input or option "Last Occurence"
    2. an input "Max Offset"

affected search functions:

  • Match Pattern
  • Search and Replace
  • Search/Split String



Current work arounds:

  1. Last Occurence
    • search all occurences from beginning (with raising offset) until no other is found
    • reverse the string and the match/search string and calculate the real offset out of the return value
  2. Max Offset
    • Search the entire string starting from the offset and check if the match is inside the limit
    • Split the string at the end and search in the new one

This work arounds are not as effective as it could be done in core LabVIEW.

Active Participant

For Last Occurence, what's wrong with just putting Reverse String in before you execute the search?


And for Max Offset, is there any reason why you can't use String Subset and then do the search on the subset?


Neither of those two options take up a whole lot of screen space, so I don't see the advantage of your Idea.

Active Participant
Active Participant

I still do see advantages:

This work arounds are not as effective as it could be done in core LabVIEW. When implemented as a function it will be quicker and more memory effective. And when NI realizes it as SubVIs they can probably write more optimized code than me.


Not sure if reverse string is optimized by the LabVIEW compiler. Getting a copy of a big string is a disadvantage.

Doing a String Subset and searching on it could produce a copy of the string in the memory. And shoud the offset input of the search VIs be removed? This could also be done with a String Subset. 



And the code for finding the last occurence looks a bit complicated and is not tiny little:

Find last occurence - Search and Find.png


Active Participant

Ah, you're also looking for the index of the last match, I didn't realise that bit.