【修改字符串截取BUG】

This commit is contained in:
weizhihong 2023-04-11 14:12:34 +08:00
parent f38c3bd1ba
commit dc461b9fce

View File

@ -118,19 +118,21 @@ public class VoiceDiscriminateResult {
public int[] getPinYinGroupAtOriginStartAndEndIndex(int index) {
String group = getGroup(index); // 获取到group
int[] indexArr = new int[2]; // 索引数组
int readIndex = 0;
// 读取起始位置group长度读取结束位置
int groupLen = group.length(), readIndex = 0, endIndex = 0;
String pinYin = null;
for (int i = 0, len = contentPinYinArr.length; i < len; i ++) {
pinYin = contentPinYinArr[i];
if (Objects.equals(group.substring(readIndex, readIndex + pinYin.length()), pinYin)) { // 字符一致
endIndex = readIndex + pinYin.length();
if (groupLen >= endIndex && Objects.equals(group.substring(readIndex, endIndex), pinYin)) { // 字符一致
if (readIndex == 0) { // 如果是0代表刚开始匹配记录开始索引
indexArr[0] = i;
}
readIndex = readIndex + pinYin.length();
readIndex = endIndex;
} else { // 字符不一致重新匹配位置
readIndex = 0;
}
if (readIndex == group.length()) { // 结束位置
if (readIndex == groupLen) { // 结束位置
indexArr[1] = i;
break;
}