【发布时间】:2017-09-18 21:21:20
【问题描述】:
我有一个字符串对象,我需要检查它是否包含另一个字符串。这就像检查“Hello World”是否包含世界“World”。
我该怎么做?
【问题讨论】:
标签: android
我有一个字符串对象,我需要检查它是否包含另一个字符串。这就像检查“Hello World”是否包含世界“World”。
我该怎么做?
【问题讨论】:
标签: android
如果你只是想检测一个特定的字符串是否包含在你的源字符串中,你可以这样做
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
.....
【讨论】:
尝试一次……对我有用…… 使用关键字
包含
和
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 {
}
【讨论】:
试试这个..
String text = "Hello World.";
if(text.contains("World')){
//Do something
}
else {
//Do something
}
【讨论】: