Strip whitespace from a string/Top and tail: Difference between revisions

Added Wren
m (→‎{{header|Raku}}: .perl -> .raku)
(Added Wren)
Line 2,588:
RosettaCode
RosettaCode
</pre>
 
=={{header|Wren}}==
In Wren 'whitespace' is defined as: space, tab, carriage return, and line feed characters. To trim off other non-printing characters such as form feed and vertical tab, you need to do a little more work.
<lang ecmascript>var a = " \t\r\nString with leading whitespace removed"
var b = "String with trailing whitespace removed \t\r\n"
var c = " \t\r\nString with both leading and trailing whitespace removed \t\r\n"
var d = " \t\r\n\f\vString with leading whitespace, form feed and verical tab characters removed"
System.print("'%(a.trimStart())'")
System.print("'%(b.trimEnd())'")
System.print("'%(c.trim())'")
System.print("'%(d.trimStart(" \t\r\n\f\v"))'") // similar overloads of trimEnd and trim exist</lang>
 
{{out}}
<pre>
'String with leading whitespace removed'
'String with trailing whitespace removed'
'String with both leading and trailing whitespace removed'
'String with leading whitespace, form feed and vertical tab characters removed'
</pre>
 
9,476

edits