增加字符串倒序重复字符约束条件
This commit is contained in:
parent
ff5c06ec45
commit
eee23bdd1e
@ -398,4 +398,26 @@ public class WStringUtil {
|
|||||||
return str.substring(0, unRepeatCharIndex + 1);
|
return str.substring(0, unRepeatCharIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 倒叙截取重复字段
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* @param repeatChar
|
||||||
|
* @param minRepeatCount
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String cutContinuityRepeatCharDesc(String str, char repeatChar, int minRepeatCount) {
|
||||||
|
int repeatCount = 0;
|
||||||
|
for (int i = str.length() - 1; i >= 0; i--) {
|
||||||
|
if (str.charAt(i) != repeatChar) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
repeatCount++;
|
||||||
|
}
|
||||||
|
if (repeatCount < minRepeatCount) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return cutContinuityRepeatCharDesc(str, repeatChar);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user