简体   繁体   中英

How to parse an array from a certain spot?

My java program takes in a line of inputs, for example:

q 1 1 K 2 2 B 3 3: 2 2 5 4

I want my program to read everything to the right of the colon. I converted it to an array, but I don't want to simply start the array at the index that's right after the colon ie

array[9]

because not all of my inputs will have 9 elements before the colon, some inputs may have more or less. Is there any way to parse the array starting with the element right after the colon, regardless of how many elements are before the colon?

使用正则表达式删除:之前的子字符串,然后将新字符串转换为数组。

如果您不想使用正则表达式(可能很难阅读和编写),那么只要您真正需要的是一个简单的indexOf就足够了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM