- Mon Apr 18, 2016 5:52 am
#45688
Another useful word-related function could be one that returns the 'position' of a specified word from within the string?
eg: let relative_position_within_string = wordpos("one two three four", "three")
(variable name is greater than new capped length of 10, but just given as example for clarity)
... returns 3
That alone could be useful, but especially if there were wordsleft() and wordsright() functions, cos then you could do things like...
let msg = "one two three four"
let pos = wordpos(msg, "three")
let left_bit = wordsleft(msg, pos-1)
let right_bit = wordsright(msg, pos)
... returning leftbit="one two", and right_bit="three four"
Thinking about it some more...
wordsleft() and wordsright() might even take a 3rd optional parameter to specify how MANY words were returned from the left or right of pos split point, and return them all if omitted.
Could be a very handy word 'suite' for dealing with parsing of strings by words instead of by characters, ie: the word equivalents to character-based instr(), left(), mid() etc.