Search code examples
nim-lang

Pythonic string.replace() in Nim?


How to replace some string with Nim ?

var pythonista:string = "Power of Python!"
echo pythonista

Solution

  • First, you need to import strutils module. Strutils is the module that defines several common functions for working with strings.

    So the code will be like this:

    import std/strutils
        
    var pythonista:string = "Power of Python!"
    echo pythonista
    echo "============"
    echo pythonista.replace("Python!", "Nim :)")
    echo "============"