Page 1 of 1

how to remove line jump/break with ruby

Posted: Mon Jan 04, 2021 3:20 am
by ErvSoft
Hello everyone, I have been a user since 2016 and I need help at this time:

I have the following scheme (attached fsm 3.0.6 file):
Image


Grand piano

Electric Piano 1

Clavinet

and I need to remove the jump / line breaks with ruby so that it looks like this:

Grand piano
Electric Piano 1
Clavinet

I found a module called 'Format String' but I don't know how to use it,
how to achieve it ?

Re: how to remove line jump/break with ruby

Posted: Mon Jan 04, 2021 5:03 am
by trogluddite
This line of Ruby code should do what you want. It removes only the empty lines from a multi-line string...

Code: Select all

output @in.gsub(/^\s*$/, "")

Yes, I know - it looks like it should be a syntax error in any sensible coding language! :lol:

The gsub part is simple enough; it means "Globally SUBstitute" - i.e. search and replace. It takes two arguments - a thing to look for, and a thing to replace it with. The replacement here is easy; an empty string - replace with nothing = delete.

The search term, /^\s*$/ is what's called a regular expression. It's a way of saying that you want to match a pattern rather than a specific string (like the * and ? wild-cards from file-dialogs on steroids). In this case, we don't want to remove all whitespace, and not even every line-ending - a regular expression makes it possible to express "only a blank line and its line ending".

Re: how to remove line jump/break with ruby

Posted: Fri Jan 15, 2021 5:00 pm
by ErvSoft
Thanks Trog: D
now it's working wonderfully,
I studied the code library of Ruby's official website and nothing worked for me, ¿ is there a specific book or dictionary for flowstone Ruby?

I had elaborated another method without ruby but it also inserts line breaks in the menu, but I think it can also be useful to someone so I will attach the scheme with the 2 elaborated methods:

ErvSoft - Favorites Menu (Other method).fsm
Favorites Menus with Ruby and without Ruby
(32.55 KiB) Downloaded 1010 times


There are 2 menus that have the function of inserting an element into the table Strings of favorites,

the first is with Ruby which eliminates the line breaks,
and the second is without ruby, using the logical components of fsm.

I hope this works, thanks again: D

Re: how to remove line jump/break with ruby

Posted: Fri Jan 15, 2021 9:55 pm
by trogluddite
ErvSoft wrote:¿ is there a specific book or dictionary for flowstone Ruby?

Sadly not - and this presents a great difficulty for learning Ruby in FlowStone. The official User Guide only teaches the parts which are unique to FlowStone; we are expected to learn the remainder of Ruby elsewhere. However, many internet Ruby tutorials and examples do not work inside FlowStone, because "RubyEdit" primitives are not like typical "stand alone" Ruby programs. IMHO, it is best to learn the basics of Ruby outside of FlowStone, and afterwards to learn what is different about FlowStone. We try our best to help people on the forums, but it is a difficult place to teach and to learn a whole programming language.