判断一个字符串是否包含另一个字符串(用java但是不能用index()这个函数)
生活随笔
收集整理的這篇文章主要介紹了
判断一个字符串是否包含另一个字符串(用java但是不能用index()这个函数)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄:
一.方法介紹
二.圖示意
三.源代碼
一.方法介紹
判斷一個字符串str1是否包含另一個字符串str2:
1.取str2的第一個字符一次和str1的字符依次比較,知道找到相等的字符為止或者找完整個str1的length.
2.當找到相等的字符后,在str2長度內str2與str1依次進行比較
二.圖示意
三.源代碼
JDK中java.lang.String.indexOf(char[], int, int, char[], int, int, int)源碼:
/*** Code shared by String and StringBuffer to do searches. The* source is the character array being searched, and the target* is the string being searched for.** @param source the characters being searched.* @param sourceOffset offset of the source string.* @param sourceCount count of the so
總結
以上是生活随笔為你收集整理的判断一个字符串是否包含另一个字符串(用java但是不能用index()这个函数)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: git之Pushing to the r
- 下一篇: Android之UI线程与子线程交互设计