string difinition
NimStringDesc {.compilerproc, final.} = object of TGenericSeq
data: UncheckedArray[char]
NimString = ptr NimStringDesc
strings are dynamically resized, have a length field
and are zero-terminated, so they can be casted to C
strings easily
we don’t use refcounts because that’s a behaviour
the programmer may not want
cstring and nim string conversation
var cstr:cstring
var nimstr = $cstr
cstr = cstr.cstring
``
## string and sequence conversation
``` nim
var s: seq[char] = @['A', 'b', 'C']
var t: string = cast[string](s)
import sequtils
var s = toSeq("abc".items)
proc toString(str: seq[char]): string =
result = newStringOfCap(len(str))
for ch in str:
add(result, ch)
echo toString(s)