如何在android中找到String中的指定文本?

时间:2017-09-18 21:21:21

标签: android

我有一个String对象,我需要检查它是否包含另一个字符串。这有点像检查" Hello World"包含世界"世界"。

我该怎么做?

3 个答案:

答案 0 :(得分:0)

如果您只想检测特定字符串是否包含在您的源字符串中,您可以执行此操作

String source = "like here is the string "hellohowareyou" and i want to extract the world "how" ...it that possible how ???? android" If(source.contains("here is the")) ..... else .....

答案 1 :(得分:0)

尝试一次......为我工作.... 使用关键字

  

包含

  

toLowerCase()

你可以实现你想要的解决方案......这样

String text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";

if(text .toLowerCase().contains(text.toLowerCase())){
}
else {

}

答案 2 :(得分:0)

试试这个..

  String text = "Hello World.";

   if(text.contains("World')){
   //Do something
  }
  else {
 //Do something
 }