POV-Ray : Newsgroups : povray.general : substr issues Server Time
5 Nov 2024 03:20:49 EST (-0500)
  substr issues (Message 1 to 1 of 1)  
From: Nicolas Alvarez
Subject: substr issues
Date: 12 Nov 2007 18:22:18
Message: <4738e02a@news.povray.org>
So... The reason why my whole map was shifted by one tile was a problem 
on my string[]-to-int[][] conversion. Apparently substr is 1-based. You 
can notice it on the manual from the example:

	substr("ABCDEFGHI",4,2) evaluates to the string "DE".

But it's not explicitly stated that P is 1-based.

#declare String = "abcd";
#declare I=0;
#while(I<strlen(String)+1)
#debug concat("Character ", str(I,0,0), " is '",
substr(String,I,1),"'\n")
#declare I=I+1;
#end

Passing 0 as P gives an empty string. 1-4 give the characters. Anything 
outside that range is an error. Why P=0 -> empty string? If it's 
one-based, shouldn't 0 give an error, just like -1 would in a zero-based 
index? And why 1-based?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.