• msd@infoserv.dk
  • +45 21402120
  • Go right

Leetspeak Nim

Yes, Leetspeak was a thing...

This code shows som string mangling and access to argv command line items.

import std/strutils
import std/os

proc leetspeak(s: string): string =
  let r = s.toUpper()
  const leetfabet = [("E","3"), ("B","8"), ("C","["), ("L","1"), ("O","0"), ("A","4")]
  return r.multiReplace( leetfabet )

proc main() =
  for i in countup(1,paramCount()):
    if i>1:
      stdout.write " "
    stdout.write leetspeak(paramStr(i))
  stdout.write "\n"
  stdout.flushFile()

when isMainModule:
  main()

Compile and run with:

nim c -r leet.nim Hello World
Posted in Nim

Leave a Reply

Your email address will not be published. Required fields are marked *