Hi gsingh93,
the following should work:
proc main() =
var test = "Hello World"
echo test[5 .. test.len]
main()
(I found this by google search.)
That doesn't crash, but more correct is [6 .. <test.len], since ranges are inclusive. The < is short-hand for "minus 1". The result is " World" (string of length 6==11+1-6) either way.
I recommend the ^ operator. The ^ operator works in all bracket expressions.
proc main() =
var test = "Hello World"
echo test[5 .. ^1]
# this is transformed by the compiler to this expression
echo test[5 .. (len(test)-1)
# 1 here can be any symbol and any expression
echo test[5 .. ^(test.len-test.high)]
# and test can also be any symbol. It's a simple rewrite rule.
main()
Anyone familiar with Python (the most commonly taught introductory programming language, and, most importantly, esr-approved) should be used to to negative indices.
(Nim has good reason for using ^ instead of -, but the idea is the same.)
IMHO, avoiding it (ex test[6 ..< test.len) is just bad style.