Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d language
communitycreator

The strip() method in D programming language

NDUKWE CHIDERA K.

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 a range variable that can either be an array or a tuple.

  • element_value: The element that will be stripped of the range_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 function
void 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 variable
writeln(strip([01.0, 0.04, 0.06, 0.0],0).length);
}

Explanation

  • Line 2: We use writeln to import the stdio module.
  • Line 3: We import the std.algorithm.mutation module which holds the strip() method.
  • Line 6: We start the main function which returns nothing, such as void.
  • Lines 7–10: We used the writeln method to print to screen the output of the strip() method.
  • Line 13: We use the .length property of arrays in D language to return the length of the stripped value.

RELATED TAGS

d language
communitycreator
RELATED COURSES

View all Courses

Keep Exploring