2012-09-29 24 views
-5

另請參閱:
How to see if a substring exists inside another string in Java 1.4
Searching for one string in another string
How to search a string in another string?如何在Java字符串中查找給定單詞的存在?

我有兩個字符串,像這樣:

String str1 = "He is doing very good"; 
String str2 = "doing"; 

我想知道如何找到字符串012在字符串「做」,即使str1改變,像這樣:

str1 = "He isdoing very good"; 
+4

提問之前檢查文檔。這是最基本的。 – keyser

+0

查看文檔或Google ... https://www.google.com/search?q=how+to+find+string+in+another+string+in+java&oq=how+to+find+string+in +另一個+字符串+在+ java – Buggabill

+0

甚至只是搜索以前的SO問題。我發現這一個:http://stackoverflow.com/questions/2940114/searching-for-one-string-in-another-string和更多。 –

回答

7

最簡單的方法是

str1.contains(str2); 
相關問題