仅代码,暂无实例
/**
* 计算子字符串出现的次数
*
* @param parentStr
* @param childStr
* @return
*/
public static int getChildStrCounts(String parentStr, String childStr) {
int propsIndex = 0;
int counts = 0; // properties 出现几次代表字段嵌套几层
while (parentStr.indexOf(childStr, propsIndex) != -1) {
counts++;
propsIndex = parentStr.indexOf(childStr, propsIndex) + childStr.length();
}
return counts;
}
本文介绍了一个用于计算子字符串在主字符串中出现次数的方法。通过一个循环结构和索引定位,该方法能准确地统计出子字符串出现的总次数。
1289

被折叠的 条评论
为什么被折叠?



