在java中,如何从字符串的第一个字符中删除字符串值?
我想从mobileNumber中删除仅在前三个字符处包含+91的countrycode在java中,如何从字符串的第一个字符中删除字符串值?,java,Java,我想从mobileNumber中删除仅在前三个字符处包含+91的countrycode String countrycode = +91; String mobileNumber = 123917890; if (mobileNumber.contains(countrycode)){ int v = countrycode.length(); String phonenumber = mobileNumber.substring(v); System.out.pri
String countrycode = +91;
String mobileNumber = 123917890;
if (mobileNumber.contains(countrycode)){
int v = countrycode.length();
String phonenumber = mobileNumber.substring(v);
System.out.println(phonenumber);
} else {
System.out.println("mobile number doesn't have country code");
}
但在mycode中,如果mobileNumber包含整个字符串,则它将从mobileNumber中删除91
获取输出:
3917890
但如果包含三个字符,我想在第一个字符串中删除countrycode。如何创建该类型的条件?如果找到,可以使用字符串替换将+91替换为空白
String countrycode = +91;
String mobileNumber = 123917890;
String noCountryCode = mobileNumber.replace("+91", "");
System.out.println(noCountryCode);
如果找到,可以使用字符串替换将+91替换为空白
String countrycode = +91;
String mobileNumber = 123917890;
String noCountryCode = mobileNumber.replace("+91", "");
System.out.println(noCountryCode);
我得到了答案,谢谢大家帮助我 很简单
String countrycode = +91;
String mobileNumber = 123917890;
if (mobileNumber.contains("+" + countrycode)){
int v = countrycode.length();
String phonenumber = num_code.substring(v);
System.out.println(phonenumber);
} else {
System.out.println("mobile number doesn't have country code");
}
现在它正在按预期的结果工作。我得到了我的答案,感谢大家对我的帮助 很简单
String countrycode = +91;
String mobileNumber = 123917890;
if (mobileNumber.contains("+" + countrycode)){
int v = countrycode.length();
String phonenumber = num_code.substring(v);
System.out.println(phonenumber);
} else {
System.out.println("mobile number doesn't have country code");
}
现在它正在按预期的效果工作。谢谢您的帮助,我已经为它做好了准备。请检查我的答案一次,并给我你的反馈。谢谢你的帮助,我得到了它的适当条件。请检查我的答案一次,并给我你的反馈。