Java 字符串与子字符串比较
我用了两个字符串native=“Java 字符串与子字符串比较,java,android,Java,Android,我用了两个字符串native=“+8801723519932”和local=“01723519932”, 如何比较两个字符串,以在变量中从本机“更改”获取+88。不使用子字符串公共a类{ native = "+8801723519932" local = "01723519932" change = ? **Compare both strings:-** if(native.equals(local)){ System.out.println("Match"); }else{
+8801723519932
”和local=“01723519932
”,
如何比较两个字符串
,以在变量
中从本机“更改”获取+88
。不使用子字符串
公共a类{
native = "+8801723519932"
local = "01723519932"
change = ?
**Compare both strings:-**
if(native.equals(local)){
System.out.println("Match");
}else{
System.out.println("Not Match");
}
**Get +88 from given string without using subString.**
if(native.indexOf("+88")>=0){
System.out.println("+88");
}
公共静态void main(字符串[]args){
//TODO自动生成的方法存根
字符串nativea=“+8801723519932”;
字符串local=“01723519932”;
字符串str[]=nativea.split(本地);
对于(int i=0;i
为什么“不使用子字符串”indexOf
和substring
组合可能是最简单的方法。这是您需要的吗?可能是重复的谢谢,我已经完成了。
public class a {
public static void main(String[] args) {
// TODO Auto-generated method stub
String nativea="+8801723519932";
String local = "01723519932";
String str[]=nativea.split(local);
for (int i = 0; i < str.length; i++) {
String string = str[i];
System.out.println(string);
}
}
}