Hi, I get string: `id: 123, price: 29,99, isAvaila...
# getting-started
i
Hi, I get string:
id: 123, price: 29,99, isAvailable: true
I try to get value of those variables:
Copy code
val object= string.trim().removeSurrounding("{", "}").split(",").map {
    it.split(":")[1].trim()
}

val id = productString[0]
val price = productString[1]
val isAvailable= productString[2].toBooleanOrNull()
The problem is
price
. It cointains
,
between 29 and 99 and it makes error. How I can avoid dividing price on two parts in that case? I don't want to use
.
instead of
,
s
.
is the standard for decimals. if you really need to use
,
, then you should pass it as a string. also, a json parsing library would probably be more convienient
s
Simple solution would be to change the first
split
from
split(",")
to
split(", ")
(with an additional space after the comma). That will work if you can be sure that commas between entries will always be followed by a space.
1
i
Thank you all
e
or set up NumberFormat to parse it in a locale that uses comma as the decimal separator
j
I concur with @Steve Georgakis, though. You should really consider a proper serialization format and corresponding library, if you're going to deal with several of these
👍 1