Zane W
02/02/2024, 10:39 AM$variable
in an already instantiated string instance? For example, the string template contains the $variable
pattern is parsed from an external file, and I want to auto interpolate the variables.Klitos Kyriacou
02/02/2024, 11:04 AMJoffrey
02/02/2024, 12:36 PMval rawTemplate = "Hello \$name" // $ is escaped, so it's part of the actual string
println(rawTemplate) // "Hello $name"
val myName = "Joffrey"
val s = rawTemplate.replace("\$name", myName)
println(s) // "Hello Joffrey"
See it in action in the playgroundZane W
02/03/2024, 2:21 AMreplace
has to be called many times.Joffrey
02/03/2024, 10:45 AM