The strip() method in D programming language
Overview
There are lots of language structures and inbuilt functions in the D programming language that we can use. In this shot, we will take a look at the strip() method.
What is the strip() method?
The strip() method will remove element_value from the range_value and return the range with the lement removed.
Syntax
strip(range_value,element_value)
Parameters
-
range_value: This is arangevariable that can either be an array or a tuple. -
element_value: The element that will be stripped of therange_value. All occurrences of this value will be removed.
Return value
The value returned is a range_value with all occurrences of element_value removed.
Example
The code snippet below demonstrates the usage of the strip() method.
import std.stdio;import std.algorithm.mutation;//start the main wrapper functionvoid main() {writeln(strip(" Hello welcome to eductative ",' '));writeln(strip("11456.67899511",'1'));writeln(strip("ëëêéüŗōpéêëë",'ë'));writeln(strip([1, 1, 0, 1, 1],1));//return the length of strip variablewriteln(strip([01.0, 0.04, 0.06, 0.0],0).length);}
Explanation
- Line 2: We use
writelnto import thestdiomodule. - Line 3: We import the
std.algorithm.mutationmodule which holds thestrip()method. - Line 6: We start the
mainfunction which returns nothing, such asvoid. - Lines 7–10: We used the
writelnmethod to print to screen the output of thestrip()method. - Line 13: We use the
.lengthproperty of arrays in D language to return the length of the stripped value.