简体   繁体   中英

Kotlin split string with multiple delimiter whitespace and comma

so i have string like this = "1, 2,3, 4, 5 6 7, 8,9 10"

this is the input of readline.string(), what kind of split delimiter do I need in order to create an array like this = [1,2,3,4,5,6,7,8,9,10]

i tried to use .split("\\s".toRegex()) but it doesnt want to accept another string delimiter like ","

You have one or more of spaces and/or commas between items, so you can use

"[\\s,]+".toRegex()

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