If I understand the requirements properly the `strutils.%` operator should 
work, it allows you to do `"some sentence. $1" % "hello"` which turns into 
`"some sentence. hello"` you can also do `"$1 $2" % ["Hello", "World"]` to get 
`"Hello World" or finally `"$# $#"` which will use `arg1` then `arg2`.

Here is how it'd look with your example 
    
    
    import std/[strutils, tables]
    var
      name: string
      language: string
      greeting: string
      languages: array[3, string] = ["en", "de", "fr"]
    
    let greetings = {"en": "Hi $1", "fr": "Bonjour $1", "de": "Gutentag 
$1"}.toTable
    let cgreetings = {"en": "Hi $1", "fr": "Bonjour $1", "de": "Gutentag 
$1"}.toTable
    
    name = "Albert"
    
    for language in languages:
      
      echo cgreetings[language] % name, "\n"
    echo "$# $#" % ["Hello", "World"]
    
    
    Run

Reply via email to