string slice(string s, int start, int end)
string slice(string s, int start, int end, int step)
大きな文字列から文字列を抽出します。
<type>[] slice(<type>s[], int start, int end)
<type>[] slice(<type>s[], int start, int end, int step)
大きな配列からサブ配列を抽出します。
string slice(string s, int hasstart, int start, int hasend, int end, int hasstep, int step)
<type>[] slice(<type>array[], int hasstart, int start, int hasend, int end, int hasstep, int step)
スライス構文に対応した汎用目的のシグネチャ。
hasstartが0なら、startを無視して0を使用します。
hasendが0なら、endを無視して配列の長さを使用します。
hasstepが0なら、stepを無視して1を使用します。
-
これは、
value[start:end:step]スライス構文を使用するのと等価の関数です。 -
startまたはendがマイナス値であれば、文字列/配列の最後からカウントされます。 -
計算された範囲は、元の文字列/配列の境界に制限されます。
-
stepがゼロなら、この関数は、空っぽの文字列/配列を返します。 -
stepがマイナスなら、逆順で項目が返されるので、endをstart未満にしてください。
Examples ¶
int[] nums = {10, 20, 30, 40, 50, 60}; slice(nums, 1, 3) == {20, 30}; // nums[1:3] slice(nums, 1, -1) == {20, 30, 30, 40, 50}; // nums[1:-1] slice(nums, 0, len(nums), 2) == {20, 40, 60}; // nums[0:len(nums):2] slice(nums, 0, 0, 0, 0, 1, 2) == {20, 40, 60}; // nums[::2]
| See also |