Question: I have a string like bellow:

`str = "Test(a=10, b=100, c=1.0, d=2.0)"`

and `Test` entity is:

```
data class Test(
   val a: int = 0,
   val b: Int = 0,
   val c: Double = 0.0,
   val d: Double = 0.0
)

```

What should I do to convert string `str` to `Test` entity?

Thankyou!!

Answer: 
Regexes seem like an appropriate choice here:

```
data class Test(val a: Int = 0, val b: Int = 0, val c: Double = 0.0, val d: Double = 0.0)
fun main() {
    val str = "Test(a=10, b=100, c=1.0, d=2.0)"
    print(getTest(str))
}
fun getTest(str: String): Test {
    val regex = """Test\(a=(.+), b=(.+), c=(.+), d=(.+)\)""".toRegex()
    val matches = regex.find(str)
    return matches?.groupValues?.let { groups ->
        Test(groups[1].toInt(), groups[2].toInt(), groups[3].toDouble(), groups[4].toDouble())
    } ?: Test()
}

```

If you're looking at storing objects as strings to re-instantiate them, consider serialization. Have a look [here](https://github.com/Kotlin/kotlinx.serialization).
It works

```
data class Test(
        val a: Int = 0,
        val b: Int = 0,
        val c: Double = 0.0,
        val d: Double = 0.0
)

fun main() {
    val str = "Test(a=10, b=100, c=1.0, d=2.0)"
    val numbers =  "([\\d.]+)".toRegex().findAll(str).map { it.value }.toList()
    val test = Test(
            numbers[0].toInt(), 
            numbers[1].toInt(), 
            numbers[2].toDouble(), 
            numbers[3].toDouble())
}

```