-2

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
vica
  • 1

5 Answers5

4

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 2
    Then you want to rework your question and put up a [mcve]. Because then you are doing something wrong ;-) – GhostCat May 10 '17 at 08:04
0

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

PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
0

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.

Wep0n
  • 392
  • 3
  • 15
  • Be careful about using :: like this. In 2017 :: looks like a method refernce; which is probably not want you mean here. – GhostCat May 10 '17 at 08:05
  • It's meant to be referring to a method, sorry. I've been working with PHP a little bit and they document all their methods this way. Is there a standard pseudo-code or otherwise widely-used way to do this? – Wep0n May 10 '17 at 08:24
  • Nevermind, I edited my answer, that was a stupid comment on my side – Wep0n May 10 '17 at 08:29
0

You can try to find the string like below

if( string.indexOf("READ") >= 0 ) { 
   Log.i("available", "true");
}else {
   Log.i("not available", "false");
}
Rameshbabu
  • 611
  • 2
  • 7
  • 21
0

you can also use String indexOf method. the contains method uses indexof underneath.

regards