Comparison of programming languages (string functions): Difference between revisions

Content deleted Content added
A.Brudz (talk | contribs)
Remove Perl 5 from table, as it doesn't have built-in, but functionality is implemented below
A.Brudz (talk | contribs)
Line 3,123:
In languages without a built-in trim function, it is usually simple to create a custom function which accomplishes the same task.
 
====APL====
[[APL (programming language)|APL]] can use regular expressions directly:
<syntaxhighlight lang="apl">
Trim←'^ +| +$'⎕R''
</syntaxhighlight>
Alternatively, a functional approach combining Boolean masks that filter away leading and trailing spaces:
<syntaxhighlight lang="apl">
Trim←{⍵/⍨(∨\∧∘⌽∨\∘⌽)' '≠⍵}
</syntaxhighlight>
Or reverse and remove leading spaces, twice:
<syntaxhighlight lang="apl">
Trim←{(∨\' '≠⍵)/⍵}∘⌽⍣2
</syntaxhighlight>
====AWK====
In [[AWK]], one can use regular expressions to trim: