POV-Ray : Newsgroups : povray.general : String Functions Server Time
24 Nov 2026 00:30:40 EST (-0500)
  String Functions (Message 1 to 7 of 7)  
From: Josh English
Subject: String Functions
Date: 4 Oct 2026 19:24:45
Message: <6ac2e03d$1@news.povray.org>
I'm trying another "push POV-Ray to a new level" and I'm messing around 
with strings.

Unfortunately the SDL doesn't even have a FIND function or STRIP 
function for strings.

I'm trying to roll my own and getting a bit frustrated.

Has anyone implemented string functions in the SDL? I'm not finding much 
in regular web searches these days.

Uncle Josh


Post a reply to this message

From: Bald Eagle
Subject: Re: String Functions
Date: 4 Oct 2026 20:00:00
Message: <web.6ac2e76135b30292279e2c3d25979125@news.povray.org>
Josh English <Jos### [at] joshuarenglishcom> wrote:
> I'm trying another "push POV-Ray to a new level" and I'm messing around
> with strings.
>
> Unfortunately the SDL doesn't even have a FIND function or STRIP
> function for strings.

As clipka has mentioned in the past, there's really very little in terms of
string manipulation in povray.

> 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'm not finding much
> in regular web searches these days.


Yep.   Those search engines don't return much of use anymore.

- BE


Post a reply to this message

From: Josh English
Subject: Re: String Functions
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

From: jr
Subject: Re: String Functions
Date: 5 Oct 2026 02:45:00
Message: <web.6ac346ee35b30292a90940d06cde94f1@news.povray.org>
hi,

Josh English <Jos### [at] joshuarenglishcom> wrote:
> ...
> Has anyone implemented string functions in the SDL? I'm not finding much
> in regular web searches these days.

I wrote a 'strSplit()' to convert a string to an array of strings:
<wiki.povray.org/content/User:Jr/assorted>


regards, jr.


Post a reply to this message

From: Maetes
Subject: Re: String Functions
Date: 5 Oct 2026 08:45:00
Message: <web.6ac39b6c35b3029285a601817bb7ede7@news.povray.org>
Josh English <Jos### [at] joshuarenglishcom> wrote:
> I'm trying another "push POV-Ray to a new level" and I'm messing around
> with strings.
>
> I'm trying to roll my own and getting a bit frustrated.
>
> Has anyone implemented string functions in the SDL? I'm not finding much
> in regular web searches these days.
>
> Uncle Josh

maybe some of my macros are helpful.

https://www.maetes.com/en/povray-os/ma_helpers

M


Post a reply to this message

From: GioSeregni
Subject: Re: String Functions
Date: 5 Oct 2026 11:40:00
Message: <web.6ac3c3d735b30292596bf60e59126100@news.povray.org>
I built these, in case anyone finds them useful.


#macro h2d(HexVal)
 (asc(HexVal)>64?asc(HexVal)-55:asc(HexVal)-48)
#end
#macro hex2rgb(hxStr)
 <(16*h2d(substr(hxStr,4,1))+h2d(substr(hxStr,5,1)))/255,(16*h2d(substr(hxStr,6,1))+h2d(substr(hxStr,7,1)))/255,
 (16*h2d(substr(hxStr,8,1))+h2d(substr(hxStr,9,1)))/255>
#end


Post a reply to this message

From: Leroy
Subject: Re: String Functions
Date: 4 Nov 2026 19:35:00
Message: <web.6aebcec435b30292ac7cd2e9f712fc00@news.povray.org>
Josh English <Jos### [at] joshuarenglishcom> wrote:
> I'm trying another "push POV-Ray to a new level" and I'm messing around
> with strings.
>
> Unfortunately the SDL doesn't even have a FIND function or STRIP
> function for strings.
>
> I'm trying to roll my own and getting a bit frustrated.
>
> Has anyone implemented string functions in the SDL? I'm not finding much
> in regular web searches these days.
>
> Uncle Josh

Funny you should bring up strings functions & stupidly complicated. I just was
using 2 encoded array strings and 2 vector arrays as a start to make roofs. One
of the string arrays has coded data to make polygons for the roof. While the
other has coded data to make gable ends of the roof where needed.

I use something similar to your 'split' but I combined split & strip into one
pass through a string making a substring that was decoded using the 2 vector
arrays.

I won't go into the rest of the code because it is very complicated and some
parts very stupid. I haven't clean it up yet.

I copied your code, never know when it might come in handy.

Have Fun!


Post a reply to this message

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