How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Smalltalk programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Smalltalk programming language
Table of Contents
Problem Statement
Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results:
For the purposes of this task whitespace includes non printable characters such as the space character, the tab character, and other such characters that have no corresponding graphical representation.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Smalltalk programming language
Source code in the smalltalk programming language
String extend
[
ltrim [
^self replacingRegex: '^\s+' with: ''.
]
rtrim [
^self replacingRegex: '\s+$' with: ''.
]
trim [
^self ltrim rtrim.
]
]
|a|
a := ' this is a string '.
('"%1"' % {a}) displayNl.
('"%1"' % {a ltrim}) displayNl.
('"%1"' % {a rtrim}) displayNl.
('"%1"' % {a trim}) displayNl.
You may also check:How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Phix programming language
You may also check:How to resolve the algorithm Tokenize a string with escaping step by step in the Julia programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the K programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Z80 Assembly programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the Sather programming language