/**
* 删除指定的列
*
* @param str | 参数名称 | 参数说明 | 是否必须 | 数据类型 | schema |
* @param column 6
* @return | 参数名称 | 参数说明 | 是否必须 | 数据类型 |
* @throws Exception Exception
*/
private static String removeColumn(String str, int column) throws Exception {
int startIndex = getIndexOf(str, column);
int endIndex = getIndexOf(str, column + 1);
return str.substring(0, startIndex) + str.substring(endIndex);
}
/**
* 获取该字符串第N次出现的位置
*
* @param line | 参数名称 | 参数说明 | 是否必须 | 数据类型 | schema |
* @param count 第几次出现
* @return index 索引下标
*/
private static int getIndexOf(String line, int count) {
int index = 0;
int findCount = 0;
while ((index = line.indexOf("|", index)) != -1) {
if (++findCount == count) {
return index;
}
index++;
}
throw new RuntimeException(line + "-------" + count);
}
获取该字符串第N次出现的位置
于 2022-02-11 14:55:43 首次发布