Java string - replace multiple spaces by one and t

2020-04-16 06:02发布

Suppose I have a string

s ="[    2323.2323 232.3232 0.2 0.3 3232]"

I want to split it into an array of strings by space delimiter. I also want to preserve a single space between values and ignore the multiple space.

What would be the regular expression to do this?

1条回答
Lonely孤独者°
2楼-- · 2020-04-16 06:44

First get rid of multiple spaces:

String after = before.trim().replaceAll(" +", " ");

Then Split the String up into your array using the split method

查看更多
登录 后发表回答