POV-Ray : Newsgroups : povray.general : String Functions : Re: String Functions Server Time
9 Oct 2026 07:37:50 EDT (-0400)
  Re: String Functions  
From: Josh English
Date: 4 Oct 2026 20:43:21
Message: <6ac2f2a9$1@news.povray.org>
On 10/4/2026 4:55 PM, Bald Eagle wrote:
> Josh English <Jos### [at] joshuarenglishcom> wrote:

> 
>> I'm trying to roll my own and getting a bit frustrated.
> 
> Well, as always, post your goal and the code, and we'll see what we can do.
> 
>> Has anyone implemented string functions in the SDL?
> 
> I'm certain I must have in the past.  Whether I can find it or not...
> 

I was hoping there was a quick "oh yeah and here's the link" to review.

I think I have a working strip(), split(), and join() functions, and I 
think I got there through luck more than actually thinking through the 
problem:

// ---------------------------------------------------------------------
// strip(string)
// Extract the first non-space word of a text, up to the following space
#macro strip(string)
   #local res = "";
   #local I = 1;
   #while(substr(string,I,1) = " ") #local I = I + 1; #end

   #local next_c = 0;
   #while (substr(string,I,1) != " ")
     #local res = concat(res, substr(string, I, 1));
     #local next_c = next_c + 1;
     #local I = I + 1;
     #if(I > strlen(string)) #break #end
   #end

   res

#end

// split(string)
// split a string by spaces
#macro split(string)
   #local len = strlen(string);
   #local I = 1;
   #declare res = array;

   #while(I <= len)
     #local next = strip(substr(string, I, len-I+1));
     //#debug concat("-",next, "-\n")
     #local I = I + strlen(next)+1;
     #declare res[dimension_size(res, 1)] = next;
   #end

   res

#end // macro split

// join(array)
// joins an array of strings into a single text by spaces
#macro join(arr)
   #local res = "";

   #for(I,0,dimension_size(arr,1)-1, 1)
     #local res = concat(res, arr[I], " ");
   #end

   substr(res, 1 strlen(res)-1)

#end
// ---------------------------------------------------------------------

It seems to work for my purposes, which are stupidly complicated, as always.

-- Uncle Josh


Post a reply to this message

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