nextSlice

Tries to make a fixed length slice by consuming range.

nextSlice
(
Range
T
)
(
ref Range range
,
T len
)
if (
isInputRange!Range &&
isSomeChar!(ElementType!Range)
&&
isIntegral!T
)

Parameters

range
Type: Range

A character input range. The range is consumed for each word.

len
Type: T

An integral value.

Return Value

Type: auto

At the tail a string whose length is less or equal to len, otherwise always a string of length len.

Examples

1 auto text0 = "012"; 
2 assert(text0.nextSlice(2) == "01");
3 auto text1 = "3";
4 assert(text1.nextSlice(8) == "3");
5 auto text2 = "45";
6 assert(text2.nextSlice(0) == "");
7 assert(text1.nextSlice(12_34_56) == "");
8 auto ut = "é_é";
9 assert(ut.nextSlice(3) == "é_é");

Meta