digitalmars.D.learn - How to get array length
- kaz (3/3) May 22 2014 Is there a way to get the length of an array out of slice bracket
- Brad Anderson (9/12) May 22 2014 Just use .length:
- kaz (2/15) May 24 2014 Tks.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (7/9) May 22 2014 If you mean the length of the original array, no. Of course, the length
- kaz (2/13) May 24 2014 Tks.
- Rene Zwanenburg (5/22) May 25 2014 Also, when slicing, you can use the dollar operator to get the
Is there a way to get the length of an array out of slice bracket in D? Tks.
May 22 2014
On Thursday, 22 May 2014 at 23:22:44 UTC, kaz wrote:Is there a way to get the length of an array out of slice bracket in D? Tks.Just use .length: void main() { import std.stdio; auto a = new int[5]; auto b = a[]; writeln(a.length, " ", b.length); }
May 22 2014
On Thursday, 22 May 2014 at 23:24:30 UTC, Brad Anderson wrote:On Thursday, 22 May 2014 at 23:22:44 UTC, kaz wrote:Tks.Is there a way to get the length of an array out of slice bracket in D? Tks.Just use .length: void main() { import std.stdio; auto a = new int[5]; auto b = a[]; writeln(a.length, " ", b.length); }
May 24 2014
On 05/22/2014 04:22 PM, kaz wrote:Is there a way to get the length of an array out of slice bracket in D? Tks.If you mean the length of the original array, no. Of course, the length of the slice is trivial: slice.length. The following article explains how slices don't know about other slices (including the original array): http://dlang.org/d-array-article.html Ali
May 22 2014
On Thursday, 22 May 2014 at 23:26:02 UTC, Ali Çehreli wrote:On 05/22/2014 04:22 PM, kaz wrote:Tks.Is there a way to get the length of an array out of slice bracket in D? Tks.If you mean the length of the original array, no. Of course, the length of the slice is trivial: slice.length. The following article explains how slices don't know about other slices (including the original array): http://dlang.org/d-array-article.html Ali
May 24 2014
On Sunday, 25 May 2014 at 06:50:14 UTC, kaz wrote:On Thursday, 22 May 2014 at 23:26:02 UTC, Ali Çehreli wrote:Also, when slicing, you can use the dollar operator to get the length of a slice: auto arr = [1, 2, 3, 4]; auto slice = arr[$/2 .. $]; // the last half of the array, [3, 4]On 05/22/2014 04:22 PM, kaz wrote:Tks.Is there a way to get the length of an array out of slice bracket in D? Tks.If you mean the length of the original array, no. Of course, the length of the slice is trivial: slice.length. The following article explains how slices don't know about other slices (including the original array): http://dlang.org/d-array-article.html Ali
May 25 2014