开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜