[英]Can I convert a String into Integer or assign it with a value?
I wanna ask if I can convert a String
into an int
or give the String a value. 我想问一下是否可以将
String
转换为int
或为String赋值。
Here is my Code: In my first line of the Method I generate a customer number for example "KU605-43", "CU629-34", "YT634-45".... as a String, 这是我的代码:在方法的第一行中,我生成一个客户编号,例如字符串形式的“ KU605-43”,“ CU629-34”,“ YT634-45”...。
In the next line I take out my number for example of the first example 60543. 在下一行中,我拿出我的电话号码,例如第一个示例60543。
I try to ParseInt
ValueOf
and so on but it still does not work. 我尝试
ParseInt
ValueOf
等,但它仍然无法正常工作。
public int wertigkeitUeberpruefen(){
String str = generate();
str = str.replaceAll("\\D+","");
}
First remove all non-numeric characters. 首先删除所有非数字字符。 Then parse the string to an integer and return it.
然后将字符串解析为整数并返回。
public int stringToParse(String str){
str = str.replaceAll("[^\\d]", "");
return Integer.parseInt(str);
}
For me the following works, where value
is the number. 对我来说,下面的作品,其中
value
是数字。
public int wertigkeitUeberpruefen(){
String str = generate();
str = str.replaceAll("\\D","");
int value = Integer.parseInt(str);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.