R. van Gasteren
R. van Gasteren

Reputation: 21

How to remove whitespace from a string in Rascal?

When you have a string in Rascal like this:

"\n\tThis is a specification of a toy Transaction.\n\tVia a transaction money
can be transfered between two accounts\n"

Or

        This is a specification of a toy Transaction.
        Via a transaction money can be transfered between two accounts

How can I remove the whitespace in the middle of the string?

My solution now is to call a function that replaces '\n', '\t', and '\r' but this doesn't seem like a sustainable solution. Also, the function trim only remove whitespace at the beginning and end.

Upvotes: 2

Views: 261

Answers (1)

Jurgen Vinju
Jurgen Vinju

Reputation: 6696

visit (x) { 
  case /[\t\n]/ => "" 
}

Upvotes: 2

Related Questions