discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Testing for Whitespace

NS
Nathan Sokalski
Sun, Apr 20, 2025 6:31 PM

I have several scenarios in which I want to test for whitespace. These include:

Removing leading/trailing space, tabs, etc.
2.
Deleting strings containing only whitespace characters from an array

I could, of course, do this manually, but that seems somewhat inefficient. Are there any built-in ways to do this? If not, I would like to suggest it as a requested feature. Any ideas?

Nathan Sokalski
njsokalski@hotmail.commailto:njsokalski@hotmail.com

I have several scenarios in which I want to test for whitespace. These include: 1. Removing leading/trailing space, tabs, etc. 2. Deleting strings containing only whitespace characters from an array I could, of course, do this manually, but that seems somewhat inefficient. Are there any built-in ways to do this? If not, I would like to suggest it as a requested feature. Any ideas? Nathan Sokalski njsokalski@hotmail.com<mailto:njsokalski@hotmail.com>
GH
gene heskett
Sun, Apr 20, 2025 6:47 PM

On 4/20/25 14:32, Nathan Sokalski via Discuss wrote:

I have several scenarios in which I want to test for whitespace. These include:

1.

Removing leading/trailing space, tabs, etc.
2.
Deleting strings containing only whitespace characters from an array

I could, of course, do this manually, but that seems somewhat inefficient. Are there any built-in ways to do this? If not, I would like to suggest it as a requested feature. Any ideas?

Nathan Sokalski
njsokalski@hotmail.commailto:njsokalski@hotmail.com

This would defeat, rendering useless the use of spaces or tabs to
indicate the scope of a line of code.  I make heavy use of this to write
code that has an excellent chance of running correctly provided I
haven't fat fingered a typu someplace.  I would object to this, its a
great way to write code that Just Works...  The editor does have some
warts, but this isn't one of them.

Cheers, Gene Heskett, CET.

--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.

  • Louis D. Brandeis
On 4/20/25 14:32, Nathan Sokalski via Discuss wrote: > I have several scenarios in which I want to test for whitespace. These include: > > 1. > Removing leading/trailing space, tabs, etc. > 2. > Deleting strings containing only whitespace characters from an array > > > I could, of course, do this manually, but that seems somewhat inefficient. Are there any built-in ways to do this? If not, I would like to suggest it as a requested feature. Any ideas? > > Nathan Sokalski > njsokalski@hotmail.com<mailto:njsokalski@hotmail.com> This would defeat, rendering useless the use of spaces or tabs to indicate the scope of a line of code.  I make heavy use of this to write code that has an excellent chance of running correctly provided I haven't fat fingered a typu someplace.  I would object to this, its a great way to write code that Just Works...  The editor does have some warts, but this isn't one of them. Cheers, Gene Heskett, CET. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis
AM
Adrian Mariano
Sun, Apr 20, 2025 7:19 PM

Gene, it's not about the editor but about the language.

If you're in a situation where you're doing enough string processing in
OpenSCAD that performance matters, I think you've gone down the wrong
path.  Just do this in userspace.  Or with a library that provides string
processing.  I'd rather see effort on new features go to things that
genuinely extend capability.

On Sun, Apr 20, 2025 at 2:47 PM gene heskett via Discuss <
discuss@lists.openscad.org> wrote:

On 4/20/25 14:32, Nathan Sokalski via Discuss wrote:

I have several scenarios in which I want to test for whitespace. These

include:

1.

Removing leading/trailing space, tabs, etc.
2.
Deleting strings containing only whitespace characters from an array

I could, of course, do this manually, but that seems somewhat

inefficient. Are there any built-in ways to do this? If not, I would like
to suggest it as a requested feature. Any ideas?

This would defeat, rendering useless the use of spaces or tabs to
indicate the scope of a line of code.  I make heavy use of this to write
code that has an excellent chance of running correctly provided I
haven't fat fingered a typu someplace.  I would object to this, its a
great way to write code that Just Works...  The editor does have some
warts, but this isn't one of them.

Cheers, Gene Heskett, CET.

--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.

  • Louis D. Brandeis

OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Gene, it's not about the editor but about the language. If you're in a situation where you're doing enough string processing in OpenSCAD that performance matters, I think you've gone down the wrong path. Just do this in userspace. Or with a library that provides string processing. I'd rather see effort on new features go to things that genuinely extend capability. On Sun, Apr 20, 2025 at 2:47 PM gene heskett via Discuss < discuss@lists.openscad.org> wrote: > On 4/20/25 14:32, Nathan Sokalski via Discuss wrote: > > I have several scenarios in which I want to test for whitespace. These > include: > > > > 1. > > Removing leading/trailing space, tabs, etc. > > 2. > > Deleting strings containing only whitespace characters from an array > > > > > > I could, of course, do this manually, but that seems somewhat > inefficient. Are there any built-in ways to do this? If not, I would like > to suggest it as a requested feature. Any ideas? > > > > Nathan Sokalski > > njsokalski@hotmail.com<mailto:njsokalski@hotmail.com> > > This would defeat, rendering useless the use of spaces or tabs to > indicate the scope of a line of code. I make heavy use of this to write > code that has an excellent chance of running correctly provided I > haven't fat fingered a typu someplace. I would object to this, its a > great way to write code that Just Works... The editor does have some > warts, but this isn't one of them. > > Cheers, Gene Heskett, CET. > > -- > "There are four boxes to be used in defense of liberty: > soap, ballot, jury, and ammo. Please use in that order." > -Ed Howdershelt (Author, 1940) > If we desire respect for the law, we must first make the law respectable. > - Louis D. Brandeis > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Mon, Apr 21, 2025 4:44 PM

strip only lthe trailing or leading characters

lthe

Typo: https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip > strip only lthe trailing or leading characters lthe
JB
Jordan Brown
Mon, Apr 21, 2025 4:46 PM

On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote:

Gene, it's not about the editor but about the language.  

If you're in a situation where you're doing enough string processing
in OpenSCAD that performance matters, I think you've gone down the
wrong path.  Just do this in userspace.  Or with a library that
provides string processing.   I'd rather see effort on new features go
to things that genuinely extend capability.

Nathan:  check out BOSL2's string handling, and in particular its
str_strip() function:
https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip

and str_replace_char():
https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_replace_char

On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote: > Gene, it's not about the editor but about the language.   > > If you're in a situation where you're doing enough string processing > in OpenSCAD that performance matters, I think you've gone down the > wrong path.  Just do this in userspace.  Or with a library that > provides string processing.   I'd rather see effort on new features go > to things that genuinely extend capability. Nathan:  check out BOSL2's string handling, and in particular its str_strip() function: https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip and str_replace_char(): https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_replace_char
GH
gene heskett
Mon, Apr 21, 2025 6:32 PM

On 4/21/25 12:46, Jordan Brown via Discuss wrote:

On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote:

Gene, it's not about the editor but about the language.

where I erroneously assumed this to be an editor function, my bad, but
changing that in the language strikes me as not backwards compatible. 
Please don't.

If you're in a situation where you're doing enough string processing
in OpenSCAD that performance matters, I think you've gone down the
wrong path.  Just do this in userspace.  Or with a library that
provides string processing.   I'd rather see effort on new features go
to things that genuinely extend capability.

Nathan:  check out BOSL2's string handling, and in particular its
str_strip() function:
https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip

and str_replace_char():
https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_replace_char


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Cheers, Gene Heskett, CET.

"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.

  • Louis D. Brandeis
On 4/21/25 12:46, Jordan Brown via Discuss wrote: > On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote: >> Gene, it's not about the editor but about the language. where I erroneously assumed this to be an editor function, my bad, but changing that in the language strikes me as not backwards compatible.  Please don't. >> If you're in a situation where you're doing enough string processing >> in OpenSCAD that performance matters, I think you've gone down the >> wrong path.  Just do this in userspace.  Or with a library that >> provides string processing.   I'd rather see effort on new features go >> to things that genuinely extend capability. > Nathan:  check out BOSL2's string handling, and in particular its > str_strip() function: > https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip > > and str_replace_char(): > https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_replace_char > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org Cheers, Gene Heskett, CET. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis
JB
Jordan Brown
Mon, Apr 21, 2025 9:37 PM

On 4/21/2025 11:32 AM, gene heskett via Discuss wrote:

where I erroneously assumed this to be an editor function, my bad, but
changing that in the language strikes me as not backwards compatible. 
Please don't.

The goal of any such feature would be to make it easy for somebody to
ignore whitespace in strings if they choose to.

On 4/21/2025 11:32 AM, gene heskett via Discuss wrote: > where I erroneously assumed this to be an editor function, my bad, but > changing that in the language strikes me as not backwards compatible.  > Please don't. The goal of any such feature would be to make it easy for somebody to ignore whitespace in strings *if they choose to*.
FH
Father Horton
Mon, Apr 21, 2025 9:55 PM

I’ve wondered before about adding regex capabilities, but it seems to me
it’s not a common use case and not worth the added complexity.

On Mon, Apr 21, 2025 at 4:38 PM Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:

On 4/21/2025 11:32 AM, gene heskett via Discuss wrote:

where I erroneously assumed this to be an editor function, my bad, but
changing that in the language strikes me as not backwards compatible.
Please don't.

The goal of any such feature would be to make it easy for somebody to
ignore whitespace in strings if they choose to.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I’ve wondered before about adding regex capabilities, but it seems to me it’s not a common use case and not worth the added complexity. On Mon, Apr 21, 2025 at 4:38 PM Jordan Brown via Discuss < discuss@lists.openscad.org> wrote: > On 4/21/2025 11:32 AM, gene heskett via Discuss wrote: > > where I erroneously assumed this to be an editor function, my bad, but > changing that in the language strikes me as not backwards compatible. > Please don't. > > > The goal of any such feature would be to make it easy for somebody to > ignore whitespace in strings *if they choose to*. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
GH
gene heskett
Mon, Apr 21, 2025 9:57 PM

On 4/21/25 12:46, Jordan Brown via Discuss wrote:

On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote:

Gene, it's not about the editor but about the language.

If you're in a situation where you're doing enough string processing
in OpenSCAD that performance matters, I think you've gone down the
wrong path.  Just do this in userspace.  Or with a library that
provides string processing.   I'd rather see effort on new features go
to things that genuinely extend capability.

I'm with you on this. The only string bug I know of is if you feed the
native string handler an even value like 3.0, the .0 is stripped,
leaving only the 3 when that value is embossed on a 3d print.  For my
vise screw project, its not a showstopper just a surprise, so I've not
mentioned it till now.  If that gets fixed in 2035 I likely won't notice
since I'd then be 100 yo & gone. Long term (50y) diabetic, chest full of
parts I was not born with now. I've done pretty good for a kid with an
8th grade education. That CET after my name is real, I teach EE's stuff
they should have learned in school but their prof didn't understand it
either. Math is not even an also ran, but I can discuss relativity in
terms of real world effects.

Nathan:  check out BOSL2's string handling, and in particular its
str_strip() function:
https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip

and str_replace_char():
https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_replace_char


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Thanks Jordan.

Cheers, Gene Heskett, CET.

--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.

  • Louis D. Brandeis
On 4/21/25 12:46, Jordan Brown via Discuss wrote: > On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote: >> Gene, it's not about the editor but about the language. >> >> If you're in a situation where you're doing enough string processing >> in OpenSCAD that performance matters, I think you've gone down the >> wrong path.  Just do this in userspace.  Or with a library that >> provides string processing.   I'd rather see effort on new features go >> to things that genuinely extend capability. I'm with you on this. The only string bug I know of is if you feed the native string handler an even value like 3.0, the .0 is stripped, leaving only the 3 when that value is embossed on a 3d print.  For my vise screw project, its not a showstopper just a surprise, so I've not mentioned it till now.  If that gets fixed in 2035 I likely won't notice since I'd then be 100 yo & gone. Long term (50y) diabetic, chest full of parts I was not born with now. I've done pretty good for a kid with an 8th grade education. That CET after my name is real, I teach EE's stuff they should have learned in school but their prof didn't understand it either. Math is not even an also ran, but I can discuss relativity in terms of real world effects. > Nathan:  check out BOSL2's string handling, and in particular its > str_strip() function: > https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip > > and str_replace_char(): > https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_replace_char > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org Thanks Jordan. Cheers, Gene Heskett, CET. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis
AM
Adrian Mariano
Mon, Apr 21, 2025 10:20 PM

Gene, I don't think you can consider it a bug that 3 prints as "3" instead
of "3.0".  The real bug, if you will, is that there is no way to specify
the desired format.  You can easily write code like

echo(str(x, x==round(x) ? ".0":"");

or something like that.  For those interested in more powerful number
conversion to strings, BOSL2 supplies several options:

https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#section-formatting-numbers-into-strings

On Mon, Apr 21, 2025 at 5:57 PM gene heskett via Discuss <
discuss@lists.openscad.org> wrote:

On 4/21/25 12:46, Jordan Brown via Discuss wrote:

On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote:

Gene, it's not about the editor but about the language.

If you're in a situation where you're doing enough string processing
in OpenSCAD that performance matters, I think you've gone down the
wrong path.  Just do this in userspace.  Or with a library that
provides string processing.  I'd rather see effort on new features go
to things that genuinely extend capability.

I'm with you on this. The only string bug I know of is if you feed the
native string handler an even value like 3.0, the .0 is stripped,
leaving only the 3 when that value is embossed on a 3d print.  For my
vise screw project, its not a showstopper just a surprise, so I've not
mentioned it till now.  If that gets fixed in 2035 I likely won't notice
since I'd then be 100 yo & gone. Long term (50y) diabetic, chest full of
parts I was not born with now. I've done pretty good for a kid with an
8th grade education. That CET after my name is real, I teach EE's stuff
they should have learned in school but their prof didn't understand it
either. Math is not even an also ran, but I can discuss relativity in
terms of real world effects.

Nathan:  check out BOSL2's string handling, and in particular its
str_strip() function:
https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip

and str_replace_char():


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Thanks Jordan.

Cheers, Gene Heskett, CET.

--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.

  • Louis D. Brandeis

OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Gene, I don't think you can consider it a bug that 3 prints as "3" instead of "3.0". The real bug, if you will, is that there is no way to specify the desired format. You can easily write code like echo(str(x, x==round(x) ? ".0":""); or something like that. For those interested in more powerful number conversion to strings, BOSL2 supplies several options: https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#section-formatting-numbers-into-strings On Mon, Apr 21, 2025 at 5:57 PM gene heskett via Discuss < discuss@lists.openscad.org> wrote: > On 4/21/25 12:46, Jordan Brown via Discuss wrote: > > On 4/20/2025 12:19 PM, Adrian Mariano via Discuss wrote: > >> Gene, it's not about the editor but about the language. > >> > >> If you're in a situation where you're doing enough string processing > >> in OpenSCAD that performance matters, I think you've gone down the > >> wrong path. Just do this in userspace. Or with a library that > >> provides string processing. I'd rather see effort on new features go > >> to things that genuinely extend capability. > I'm with you on this. The only string bug I know of is if you feed the > native string handler an even value like 3.0, the .0 is stripped, > leaving only the 3 when that value is embossed on a 3d print. For my > vise screw project, its not a showstopper just a surprise, so I've not > mentioned it till now. If that gets fixed in 2035 I likely won't notice > since I'd then be 100 yo & gone. Long term (50y) diabetic, chest full of > parts I was not born with now. I've done pretty good for a kid with an > 8th grade education. That CET after my name is real, I teach EE's stuff > they should have learned in school but their prof didn't understand it > either. Math is not even an also ran, but I can discuss relativity in > terms of real world effects. > > Nathan: check out BOSL2's string handling, and in particular its > > str_strip() function: > > https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_strip > > > > and str_replace_char(): > > > https://github.com/BelfrySCAD/BOSL2/wiki/strings.scad#function-str_replace_char > > > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > Thanks Jordan. > > Cheers, Gene Heskett, CET. > > -- > "There are four boxes to be used in defense of liberty: > soap, ballot, jury, and ammo. Please use in that order." > -Ed Howdershelt (Author, 1940) > If we desire respect for the law, we must first make the law respectable. > - Louis D. Brandeis > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >