Search code examples
business-basicbbj

Looking for backwards seach in string in BBx Business basic


I look for a way to search in a string, starting from the last character.

I do have a solution with a for next loop and parse the string one by one. But there must be a smarter way to do this. I have tried to do this with

pos (" "=i$)

but this statement starts from the begin


Solution

  • The loop will do, but it's slow. There is a inbuild command you can use

    I$="123 ABC DEF"
    X = POS (" "=I$,-1)
    

    This gives you the position of the last space in I$
    result of this is 7

    Another option is using MASK() which is pretty much similar to the unix "grep"