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

Content added Content deleted
(Emacs Lisp: Simplify solution)
(add bqn)
Line 458: Line 458:
WHILE ASC(A$)<=32 A$ = MID$(A$,2) : ENDWHILE
WHILE ASC(A$)<=32 A$ = MID$(A$,2) : ENDWHILE
WHILE ASC(RIGHT$(A$))<=32 A$ = LEFT$(A$) : ENDWHILE</lang>
WHILE ASC(RIGHT$(A$))<=32 A$ = LEFT$(A$) : ENDWHILE</lang>

=={{header|BQN}}==

The following program uses an AND-scan (a well known idiom for leading characters) to find the leading whitespace. The whitespace characters are then filtered out from those locations.

Composing the leading and trailing idioms removes whitespace from both sides.

<lang bqn>ws ← @+⟨9, 10, 11, 12, 13, 32, 133, 160,
5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198,
8199, 8200, 8201, 8202, 8232, 8233, 8239, 8287,
12288⟩
Lead ← (¬·∧`∊⟜ws)⊸/
Trail ← (¬·⌽·∧`·∊⟜ws⌽)⊸/

•Show Lead " fs df"
•Show Trail "fdsf asd "
•Show Lead∘Trail " white space "</lang><lang>"fs df"
"fdsf asd"
"white space"</lang>


=={{header|Bracmat}}==
=={{header|Bracmat}}==