Trim string function

Request a new command, feature, or improvement

Moderator: MSandro

Post Reply
SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Trim string function

Post by SimpleSi » Sep 12th, '17, 14:49

I'm finding I could do with a simple trim function to remove leading and trailing spaces from strings

My workaround is a bit messy and long (and only deals with one space at either end)
0.png

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Trim string function

Post by JohnM » Sep 14th, '17, 20:41

GP already has a trim function, it's just not in the palette. However, if you enter developer mode, you can open a "system palette", select the "String" class (a good place to look for handy string utilities), and find the "trim" command (bottom of second column):
Screen Shot 2017-09-14 at 4.35.37 PM.png
Once you know it exists, the easiest way to get a "trim" block is to open a workspace window, type "trim 'foo'", select that text, and invoke the "blockify" command from the menu. You can also drag blocks directly from the system palette, but you often don't get a block editable input slots.

Another way you might find it, if you don't mind using the command line, is to use the Unix/Linux "grep" command to search for the string "trim" in the GP library folder:

Code: Select all

> grep trim runtime/lib/*
runtime/lib/BlockSpec.gp:    atPut specs i (trim (at specs i))
runtime/lib/String.gp:method trim String {
The second line of the results shows that "trim" is a method defined in the class String, so it's an operation you can use on strings.

There should be easier ways to find useful operations like "trim".

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: Trim string function

Post by SimpleSi » Sep 15th, '17, 20:33

Thanks for info
and
There should be easier ways to find useful operations like "trim".
yes :)
Ok for those of us who like diving deep but newcommers with arm bands need something easier :)

Post Reply