欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java去掉数字字符串开头的0三种方法(推荐)

程序员文章站 2024-02-24 17:34:18
方式一: 例如:”0000123” (字符串必须全为数字) 处理过程: string tempstr = "0000123"; int result =...

方式一:

例如:”0000123” (字符串必须全为数字)

处理过程:

string tempstr = "0000123"; 
int result = integer.parseint(tempstr); 

result 结果:123

方式二:

例如:”0000123”

处理过程:

string str = "0000123"; 
string newstr = str.replacefirst("^0*", ""); 
system.out.println(newstr); 

打印结果:123

方式三:

例如:”0000123”

处理过程:

string str = "0000123"; 
string newstr = str.replaceall("^(0+)", ""); 
system.out.println(newstr);  

打印结果:123

以上这篇java去掉数字字符串开头的0三种方法(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。