开发者

Splitting string on white characters?

开发者 https://www.devze.com 2023-02-15 15:58 出处:网络
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:

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

精彩评论

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