Vivek Modi
06/24/2022, 9:06 AMFor example 1
val string = "Birth Control"
val searchText = "n"
Output
["Birth Co", "trol"]
For example 2
val string = "Bladder Infection"
val searchText = "i"
Actual Output
["Bladder ", "nfect", "on"]
Expect Output
["Bladder ", "nfection"]
I tried some code but example 1
is working fine but example 2
is not because I only want to split first occurrence.
val splitList = title?.split(searchText, ignoreCase = true)?.toMutableList()
splitList?.remove(searchText)
Can someone guide me how to solve this idiomatic way. ThanksThomas Urbanitsch
06/24/2022, 9:18 AM"Bladder Infection".split("i", ignoreCase = true, limit = 2)
-> [Bladder , nfection]
https://pl.kotl.in/poJnscjh-Vivek Modi
06/24/2022, 9:38 AM