Word pals
Posted:
Sat Apr 16, 2016 4:17 pm
by Electroguard
The word() is very useful for parsing words from a string.
But perhaps it's a bit lonely and could do with a pal called wordscount() to keep it company... which could then offer word() operations referenced from the end of the string as well.
A couple more pals called wordsleft() and wordsright() might make for a really great word-parsing party!
Re: Word pals
Posted:
Sat Apr 16, 2016 10:45 pm
by Mmiscool
I like the ideah if a wordcount function.
Will look to make this happen.
Re: Word pals
Posted:
Mon Apr 18, 2016 5:52 am
by Electroguard
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.