From 4e05bca96fb13780b98b2779db6382d7d35ed354 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 12:06:34 +0200 Subject: [PATCH] manual: add a note about the terminating zero for strings; refs #5596 --- doc/manual.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index 7a765ef630..6dc6794f12 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1004,6 +1004,11 @@ All string literals are of the type ``string``. A string in Nim is very similar to a sequence of characters. However, strings in Nim are both zero-terminated and have a length field. One can retrieve the length with the builtin ``len`` procedure; the length never counts the terminating zero. + +The terminating zero cannot be accessed unless the string is converted +to the ``cstring`` type first. The terminating zero assures that this +conversion can be done in O(1) and without any allocations. + The assignment operator for strings always copies the string. The ``&`` operator concatenates strings.