gpt4 book ai didi

java - 如何提取正确的字符串?

转载 作者:行者123 更新时间:2023-12-02 08:09:17 24 4
gpt4 key购买 nike

我有一个像这样的字符串:

 14.809180,56.876968,0.000000 14.808170,56.877048,0.000000 14.805100,56.877220,0.000000 14.804130,56.877338,0.000000

即,开头有一个空格,0.000000 之后也有一个空格。我只想提取 14.XYZ56.XYZ。我怎样才能做到这一点?

最佳答案

根据我的评论,尝试 String#split(...),例如:

  String test = "14.809180,56.876968,0.000000 14.808170,56.877048,0.000000 14.805100,56.877220,0.000000";
String[] tokens = test.split("[,\\s]+");
for (String token : tokens) {
System.out.println(token);
}

"[,\\s]+" 是一种正则表达式,可帮助 split 方法使用一个或多个空白字符 (\s) 或逗号分割字符串。

关于java - 如何提取正确的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7694101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com