【问题标题】:How to find the specified text in String in android?如何在android中的String中找到指定的文本?
【发布时间】:2017-09-18 21:21:20
【问题描述】:

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

我该怎么做?

【问题讨论】:

标签: android


【解决方案1】:

如果你只是想检测一个特定的字符串是否包含在你的源字符串中,你可以这样做

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 .....

【讨论】:

    【解决方案2】:

    尝试一次……对我有用…… 使用关键字

    包含

    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 {
    
    }
    

    【讨论】:

      【解决方案3】:

      试试这个..

        String text = "Hello World.";
      
         if(text.contains("World')){
         //Do something
        }
        else {
       //Do something
       }
      

      【讨论】:

        猜你喜欢
        • 2014-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多