|
![](/i/fill.gif) |
"SharkD" <mik### [at] gmail com> wrote in message
news:4ae7d67a@news.povray.org...
> Is there a function I can use to convert a string into an array?
>
> Thanks!
>
> Mike
I don't remember seeing a standard function, but it's quick to split a
string with the existing POVRay functions and a #while loop (see the 2
examples below).
If you want more sophisticated processing you'll find some macros in the
Scroll include file from the Object Collection that can left, right, centre
or full justify text strings.
Note that the examples below write the strings to the message stream and
produce only a completely black image.
Regards,
Chris B.
camera { location z look_at 0 }
light_source { <-5,30,-10> 1 }
#declare Str = "How many roads must a man walk down?";
// Convert string to array of single characters
#declare Arr = array[strlen(Str)];
#declare Ctr = 0;
#while (Ctr<strlen(Str))
#declare Arr[Ctr] = substr(Str,Ctr+1,1);
#debug concat(Arr[Ctr],"\n")
#declare Ctr = Ctr+1;
#end
// Split string on spaces
#declare Arr = array[strlen(Str)];
#declare Ctr = 0;
#declare Pos = 1;
#declare Words = 0;
#while (Ctr<strlen(Str))
#if (strcmp(substr(Str,Ctr+1,1)," ")=0)
#declare Arr[Words] = substr(Str,Pos,Ctr-Pos+1)
#declare Pos = Ctr+2;
#debug concat(Arr[Words],"\n")
#declare Words = Words+1;
#end
#declare Ctr = Ctr+1;
#end
#declare Arr[Words] = substr(Str,Pos,strlen(Str)-Pos+1)
#debug concat(Arr[Words],"\n")
#declare Words = Words+1;
Post a reply to this message
|
![](/i/fill.gif) |