获取该字符串第N次出现的位置
生活随笔
收集整理的這篇文章主要介紹了
获取该字符串第N次出现的位置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
/*** 刪除指定的列** @param str | 參數(shù)名稱 | 參數(shù)說明 | 是否必須 | 數(shù)據(jù)類型 | schema |* @param column 6* @return | 參數(shù)名稱 | 參數(shù)說明 | 是否必須 | 數(shù)據(jù)類型 |* @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次出現(xiàn)的位置** @param line | 參數(shù)名稱 | 參數(shù)說明 | 是否必須 | 數(shù)據(jù)類型 | schema |* @param count 第幾次出現(xiàn)* @return index 索引下標(biāo)*/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);}
總結(jié)
以上是生活随笔為你收集整理的获取该字符串第N次出现的位置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Svchost.exe进程CPU占用10
- 下一篇: 白户办什么信用卡容易 能批信用卡的平台在