Good morning.
I want to send split to a String such as " abc def " and receive
back an Array with the two elements String(abc) and String(def); and I want
to receive back a zero-length Array if the target is empty or contains only
white space.
The following code produces an unwanted empty string as the first element.
This also occurs when the target is a zero-length String or a String
composed only of spaces.
After all morning, I can't find the solution. Thanks for any help, Ron.
" abc def ".split("\\ s+")
=> Array("", "abc", "def")
" ".split("\\ s+")
=> Array("")
I want to send split to a String such as " abc def " and receive
back an Array with the two elements String(abc) and String(def); and I want
to receive back a zero-length Array if the target is empty or contains only
white space.
The following code produces an unwanted empty string as the first element.
This also occurs when the target is a zero-length String or a String
composed only of spaces.
After all morning, I can't find the solution. Thanks for any help, Ron.
" abc def ".split("\\ s+")
=> Array("", "abc", "def")
" ".split("\\ s+")
=> Array("")
Comment