I'm looking for a function which accepts a string as input and returns the number of the tokens of the string. Is there any ready function for this? If not, what is the correct algorithm for doing this?
For example if string = "hello world" the function should return 2.
If the string = "hello" it should return 1. If the string = " "(only spaces), it should return 0.