Skip to main content

Text.take

takerange

Group: Selections
Aliases: first, head, keep, last, left, limit, mid, right, slice, substring, tail, top

Documentation

Creates a new Text by selecting the specified range of the input. This can select a section of text from the beginning, end, or middle of the input using various criteria defined by the range parameter.

Arguments

  • range: The section of the self text to return. If a Text_Sub_Range, then the selection is interpreted following the rules of that type. If a Range, the selection is specified by two indices, from and to.

Returns

The part of the input as specified by the range parameter.

Examples

Various different ways to take part of "Hello World!"

      "Hello World!".take ..First == "H"
"Hello World!".take (..First 5) == "Hello"
"Hello World!".take (..First 0) == ""
"Hello World!".take ..Last == "!"
"Hello World!".take (..Last 6) == "World!"
"Hello World!".take (..Before " ") == "Hello"
"Hello World!".take (..Before_Last "o") == "Hello W"
"Hello World!".take (..After " ") == "World!"
"Hello World!".take (..After_Last "o") == "rld!"
"Hello World!".take (..While c->c!=" ") == "Hello"
"Hello World!".take (..Range 3 5) == "lo"
"Hello World!".take (..Range 5 Nothing) == " World!"
"Hello World!".take (..Range 5 12) == " World!"
"Hello World!".take (..Range 6 12 2) == "Wrd"
"Hello World!".take (..Every 2 first=6) == "Wrd"
"Hello World!".take (..Every 3) == "Hl Wl"
"Hello World!".take (..By_Index 0) == "H"
"Hello World!".take (..By_Index [1, 0, 0, 6, 0]) == "eHHWH"
"Hello World!".take (..By_Index [Range 0 3, 6, Range 6 12 2]) == "HelWWrd"
"Hello World!".take (..Sample 3 seed=42) == "l d"