stanza

How do I find and replace characters in a string in stanza?


Let's say I have a string val s = "_1.2V_ADC"

The period is invalid for my use case so I need to replace it with another character, like p so the final string should be "_1p2V_ADC"

Is there any easy way to do that in Stanza?


Solution

  • You can use the replace function for this:

    val s = replace("_1.2V_ADC", ".", "p")
    

    It will replace all matches of the string "." with the string "p".