i have the following in my code.
String viit = "android.permission.READ_SOCIAL_STREAM";
and
String biit = "READ";
How do i search if viit contains biit?
Please note that viit is not a sentence but more like a word.
i have the following in my code.
String viit = "android.permission.READ_SOCIAL_STREAM";
and
String biit = "READ";
How do i search if viit contains biit?
Please note that viit is not a sentence but more like a word.
Simple: you use one of the many methods on String, such as contains().
if (viit.contains(biit)) {
which will give true for an "exact" match. If you need something "more fuzzy", you would be turning to matches() fore example which takes a regular expression. Those allow for a great deal of "fine tuned" patterns to be used.
Use contains method.
String viit = "android.permission.READ_SOCIAL_STREAM";
String biit = "READ";
if(viit.contains(biit)) {
//int index = viit.indexOf(biit);
}
https://developer.android.com/reference/java/lang/String.html
Use the java String.indexOf() method.
In your example, this would be something like that:
boolean hit = viit.indexOf(biit) == -1 ? true : false;
You can omit the boolean if you don't need it, if indexOf has no hit it will return -1.
Or use the String.contains() method which gives a boolean straight away.
You can try to find the string like below
if( string.indexOf("READ") >= 0 ) {
Log.i("available", "true");
}else {
Log.i("not available", "false");
}
you can also use String indexOf method. the contains method uses indexof underneath.
regards