如何判断字符串对象中是否存在子字符串"template"(例如)?
如果它不是一个区分大小写的检查,那就太好了.
我是 Java 新手,我想知道是否有办法根据另一个字符串检查一个字符串,我已经在 Python 中像这样完成了“
text = "Tree"
if "re" in text:
print "yes, there is re exist in Tree"
Run Code Online (Sandbox Code Playgroud)
我们在java中有这样的方式来检查一个字符串是否存在于另一个字符串中吗?
编辑:我以 String 为例,我主要是在寻找像 python 那样的函数,正如我在 java 中的“in”和“not in”标题中提到的,来比较存在于另一个变量中的任何变量。
在 python 中,我可以比较数组或列表与单个字符串变量:
myList = ["Apple", "Tree"]
if "Apple" in myList:
print "yes, Apple exist"
Run Code Online (Sandbox Code Playgroud)
偶数数组vs数组:
myList = ["Apple", "Tree","Seed"]
if ["Apple","Seed"] in myList:
print "yes, there is Apple and Seed in your list"
Run Code Online (Sandbox Code Playgroud)
和单个整数vs数组 …
另请参阅:
如何查看Java中另一个字符串中是否存在子字符串1.4
在另一个字符串中搜索一个字符串如何在另一个字符串
中搜索字符串?
我有两个字符串,如下:
String str1 = "He is doing very good";
String str2 = "doing";
Run Code Online (Sandbox Code Playgroud)
我想知道如何在字符串中找到"做"这个词str1,即使str1改变如此:
str1 = "He isdoing very good";
Run Code Online (Sandbox Code Playgroud)