I have taken two string native = "+8801723519932
" , and local = "01723519932
" ,
how can I compare two strings
to get +88
in a variable
"change" from native. without using substring
.
Asked
Active
Viewed 79 times
-1

sTg
- 4,313
- 16
- 68
- 115

Barun Kumar
- 209
- 1
- 2
- 18
-
Why "without using sub string"? `indexOf` and `substring` in combination is probably the simplest way of doing this. – Luna Jul 22 '15 at 11:07
-
1Is [that](http://stackoverflow.com/a/18345060/4762282) what you need? – Ircover Jul 22 '15 at 11:25
-
possible duplicate of [Extract the difference between two strings in Java](http://stackoverflow.com/questions/18344721/extract-the-difference-between-two-strings-in-java) – Silver Quettier Jul 22 '15 at 12:03
-
1Thanks, I have finished it. – Barun Kumar Jul 23 '15 at 04:48
2 Answers
0
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");
}

Tushar Patil
- 326
- 4
- 22
0
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);
}
}
}

Shekhar
- 812
- 1
- 8
- 18