Quick actions

cmd+k|ctrl+k

Navigation

Languages

Strings with null \0 characters

Snippet info

Language

Nim

Visibility

public

Author

oderwat

Created

2016-05-31T15:26:11Z

Updated

2016-05-31T15:28:15Z

import strutils

var s = "a\0b\0c"

echo s.replace("\0", "\\0")
echo s.replace("\0", "")
echo s.repr

for c in s: write(stdout, c)
write(stdout, "\n")

proc stringToHex(s: string): string =
  result = ""
  for o,c in s:
    if o != 0:
      result.add ' '
    result.add c.int.toHex(2)

echo s.stringToHex
INFO