Splitting string on white characters?
I'm using python and 开发者_运维百科I'm simply trying to split a string on white characters (white spaces, tab, new line, etc.) and put it on an array. If I use:
result_array = result.split("\s+")
it doesn't works. What I'm doing wrong?
If you want to split on whitespace itself just use split()
with no arguments. The split()
for strings doesn't take a regular expression, though there is an re.split()
function that will allow you to split based on a regular expression if you need.
Just use
result_array = result.split()
str.split()
splits on whitespace by default and won't accept regular expressions anyway.
精彩评论