如何拆分此字符串? [英] How to split this String?

查看:126
本文介绍了如何拆分此字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拆分此字符串

 字符串信息=0.542008835米距离地面高度;

此我想只得到两位小数这样的 0.54

使用此我得到了

 的String [] = _new rhs.split(?(小于= \\\\摹....));

但我在这里面临的问题,如果字符串包含简化版,像这样的字符串的任何小数

 字符串信息=1米,地面高度;

此字符串我得到高达前4这些字符的字符串分割像 1我
我想只有数字拆分如果有小数,如何解决这个问题。


解决方案

 如果(info.contains(。))
{
       的String [] = _new rhs.split(?(小于= \\\\摹....));
}

I want to split this string

String info = "0.542008835 meters height from ground";

from this i want to get only two decimals like this 0.54.

by using this i am getting that

String[] _new = rhs.split("(?<=\\G....)");

But i am facing problem here, if string does't contain any decimals like this string

String info = "1 meters height from ground";

for this string i am getting those characters upto first 4 in the split string like 1 me. i want only numbers to split if it has decimals, How to solve this problem.

解决方案

if(info.contains("."))
{
       String[] _new = rhs.split("(?<=\\G....)");
}

这篇关于如何拆分此字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆