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)
Trim string function
Moderator: MSandro
Re: Trim string function
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):
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:
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".
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 {
There should be easier ways to find useful operations like "trim".
Re: Trim string function
Thanks for info
and
Ok for those of us who like diving deep but newcommers with arm bands need something easier :)
and
yes :)There should be easier ways to find useful operations like "trim".
Ok for those of us who like diving deep but newcommers with arm bands need something easier :)