当前位置:网站首页>Get the position of the nth occurrence of the string
Get the position of the nth occurrence of the string
2022-07-06 12:22:00 【Silence, your name】
/**
* Delete the specified column
*
* @param str | Parameter name | Parameter description | Whether must | data type | schema |
* @param column 6
* @return | Parameter name | Parameter description | Whether must | data type |
* @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);
}
/**
* Get the string number N The location of the second occurrence
*
* @param line | Parameter name | Parameter description | Whether must | data type | schema |
* @param count How many times
* @return index Index subscript
*/
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);
}
边栏推荐
- [Offer29] 排序的循环链表
- Detailed explanation of Union [C language]
- JS变量类型以及常用类型转换
- Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
- (一)R语言入门指南——数据分析的第一步
- Basic knowledge of lithium battery
- Arduino uno R3 register writing method (1) -- pin level state change
- (五)R语言入门生物信息学——ORF和序列分析
- How to add music playback function to Arduino project
- [offer9]用两个栈实现队列
猜你喜欢
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
基于Redis的分布式ID生成器
JS 函数提升和var变量的声明提升
JS变量类型以及常用类型转换
Basic operations of databases and tables ----- classification of data
Symbolic representation of functions in deep learning papers
Time slice polling scheduling of RT thread threads
arduino JSON数据信息解析
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
随机推荐
Kconfig Kbuild
基于Redis的分布式ID生成器
Knowledge summary of request
Learning notes of JS variable scope and function
Understanding of AMBA, AHB, APB and Axi
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
Talking about the startup of Oracle Database
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
Mysqldump error1066 error solution
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
JS regular expression basic knowledge learning
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
ES6 grammar summary -- Part I (basic)
C language callback function [C language]
Programmers can make mistakes. Basic pointers and arrays of C language
open-mmlab labelImg mmdetection
Arm pc=pc+8 is the most understandable explanation
GCC compilation options
Embedded startup process
Esp8266 connect onenet (old mqtt mode)