62,621
社区成员
发帖
与我相关
我的任务
分享
String str = "01.101.01.01";
str = str.substring(0,1).replace("0", "")+ str.substring(1);
str = str.replaceAll("\\.0", "\\.");
方法比较土,等待高手吧
public class TestString
{
/**
* @param args
*/
public static void main(String[] args)
{
String str = "1.01.01.01";
String[] temp = str.split("\\.");
StringBuffer sb = new StringBuffer();
for (int i = 0; i < temp.length; i++)
{
sb.append(Integer.parseInt(temp[i]));
if (i != temp.length - 1)
{
sb.append(".");
}
}
System.out.println(sb.toString());
}
}