Trying to write a short method so that I can parse a string and extract the first word. I have been looking for the best way to do this.
I assume I would use s
The simple one I used to do is
str.contains(" ") ? str.split(" ")[0] : str
Where str is your string or text bla bla :). So, if
str is having empty value it returns as it is.str is having one word, it returns as it is.str is multiple words, it extract the first word and return.Hope this is helpful.