当前位置:网站首页>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);
}
边栏推荐
- Types de variables JS et transformations de type communes
- ESP8266连接onenet(旧版MQTT方式)
- Pat 1097 duplication on a linked list (25 points)
- Arduino JSON data information parsing
- ES6 grammar summary -- Part I (basic)
- Kconfig Kbuild
- Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
- Walk into WPF's drawing Bing Dwen Dwen
- By v$rman_ backup_ job_ Oracle "bug" caused by details
- [golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
猜你喜欢
JS variable types and common type conversions
Single chip Bluetooth wireless burning
Analysis of charging architecture of glory magic 3pro
Kconfig Kbuild
Several declarations about pointers [C language]
Oppo vooc fast charging circuit and protocol
Vscode basic configuration
Basic knowledge of lithium battery
Common properties of location
Time slice polling scheduling of RT thread threads
随机推荐
ES6 grammar summary -- Part 2 (advanced part es6~es11)
单片机蓝牙无线烧录
Who says that PT online schema change does not lock the table, or deadlock
列表的使用
Variable parameter principle of C language function: VA_ start、va_ Arg and VA_ end
Rough analysis of map file
AMBA、AHB、APB、AXI的理解
[Offer29] 排序的循环链表
arduino获取数组的长度
STM32 how to locate the code segment that causes hard fault
[offer9]用两个栈实现队列
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
I2C bus timing explanation
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
Whistle+switchyomega configure web proxy
Important methods of array and string
arduino获取随机数
程序员老鸟都会搞错的问题 C语言基础 指针和数组
CUDA C programming authoritative guide Grossman Chapter 4 global memory
[Offer18]删除链表的节点