2
I have the following text file called fullResponse
<Sum> [stat]player_ammo_restored = 3447
<Sum> [stat]player_climb_assists = 2102
<Sum> [stat]player_climb_coops = 2612
<Sum> [stat]player_damage = 25129585
There are more lines, this is the beginning of the file.
I need to make a substring
to get the data. Doing
val player_ammo_restored = fullResponse
.substringAfter("<Sum> [stat]player_ammo_restored = ")
.substringBefore("\n<Sum>").toInt()
It works, and it brings the value 3447.
But if for example, if the line <Sum> [stat]player_climb_assists = 2102
not exist and I try to do
val player_climb_assists = fullResponse
.substringAfter("<Sum> [stat]player_climb_assists = ")
.substringBefore("\n<Sum>").toInt()
it returns the first line of the file and gives error in converting to int pq instead of bringing the value it brings the full line (<Sum> [stat]player_ammo_restored = 3447
)
How do the substring
bring an empty string if there is no line I am searching for?
perfect, it was just that
– Marceloawq