brainfade with slicing
BlitzMax Forums/BlitzMax Beginners Area/brainfade with slicing
| ||
Hi, I'm not getting the expected results with slicing:Strict Local test[4] test[0] = 10 test[1] = 20 test[2] = 30 test[3] = 40 Print Len(test) test = test[1..2] Print Len(test) I'm expecting to see an array of length 2 but I get 1! If I do test=test[2..2] I'd expect a single array slot but I get a length of 0, weird. What am I doing wrong please? Oh, also, is slicing 1-based? I assumed so as I thought 0..0 was a was to clear an array (instead of array=null) |
| ||
From the doc The length of the returned slice is always EndIndex - StartIndex elements long does this explain it? |
| ||
When slicing the upper limit is ONE MORE than you want to keep in the array. Think of it as the point where you want the array sliced from, so it it actually gets chopped from that point forward. This one got me initially, as well. |
| ||
Tonyg: yeah that helps thanks, I couldn't find slicing in the docs. JazzieB: got it! Also it seems that slicing is zero based after I did some testing. |
| ||
Slices are in the Language reference. |
| ||
thx |