本文介绍了如何在另一个字符串中搜索字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在另一个字符串中搜索字符串?
How would I search for a string in another string?
这是一个我正在谈论的例子:
This is an example of what I'm talking about:
String word = "cat";
String text = "The cat is on the table";
Boolean found;
found = findInString(word, text); //this method is what I want to know
如果字符串word在字符串中 text,方法findInString(String,String)返回true,否则返回false。
If the string "word" is in the string "text", the method "findInString(String, String)" returns true else it returns false.
推荐答案
这已经在字符串类:
String word = "cat";
String text = "The cat is on the table";
Boolean found;
found = text.contains(word);
这篇关于如何在另一个字符串中搜索字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!