08-25-2025 04:42 AM
how to get the last index of a string array? the array size is always changes in certain situations
08-25-2025 04:45 AM - edited 08-25-2025 05:00 AM
Hi sinclair,
@sinclair15 wrote:
how to get the last index of a string array? the array size is always changes in certain situations
You want to know the ArraySize? Then why don't you determine the ArraySize?
(When you want to get the value of the last array element (of a 1D array) then use DeleteFromArray…)
08-25-2025 06:10 AM
Ok gerd thankyou, the problem has been resolved
08-25-2025 06:14 AM - edited 08-25-2025 06:14 AM
Hi sinclair,
@sinclair15 wrote:
the problem has been resolved
In which way did you solve the problem?
(You know in a public forum it's important to provide solutions to questions with some explanations. Others may benefit from your detailed answer - the same as you learned from asking…)
08-25-2025 10:56 AM
@sinclair15 wrote:
how to get the last index of a string array? the array size is always changes in certain situations
For any array (not just an array of strings, what I assume you mean by "string array"), the index of the last element (I assume that's what you mean by "last index") is the array size minus one.
08-25-2025 04:53 PM
@GerdW wrote:
Hi sinclair,
@sinclair15 wrote:
how to get the last index of a string array? the array size is always changes in certain situations
You want to know the ArraySize? Then why don't you determine the ArraySize?
(When you want to get the value of the last array element (of a 1D array) then use DeleteFromArray…)
Note that when you don't wire the "index" input of "Delete from Array", it deletes the last element.
08-25-2025 07:12 PM
Obviously I am not versed in reading between the lines, but from the question, I assume ....
Of course the deeper question is why the array size is constantly changing and why they are interested in the "last index" (sic). Maybe they just want to determine the location where to append new data (e.g. using the misguided "insert into array"), something that is not necessary with the right primitive (i.e. "built array", possibly in concatenate mode). 😄
Sometimes the code can be rewritten to keep the array size constant and be less taxing on the memory manager, but for that we would need more detail about the requirements....
08-26-2025 12:48 AM - edited 08-26-2025 12:48 AM
Hi,
@altenbach wrote:
- They want to keep the array intact. (Delete from array does not do that, so we need to branch the array first and continue with the intact version).
I never mentioned to use the array output of DeleteFromArray, I just suggested to use the "deleted element" output of that node.
For the broader audience: DeleteFromArray can be used as a shortcut to "index the last element of an 1D array".
(I know that you know this, Christian. 🙂 )
08-26-2025 01:08 AM
I sure hope that "delete from array" can eliminate the creation of the shortened array output if nothing is connected to it. I have never done any benchmarking.
(Back in the nineties, "delete from array" did not even exist and I still rarely use it) 😄
08-26-2025 04:37 AM
@altenbach wrote:
...
(Back in the nineties, "delete from array" did not even exist and I still rarely use it) 😄
You are right, and I made myself a polymorphic VI with that function. I called it "Pop Array Element" since I had some Perl- experience and there this task was named this way 😁
It also took me some time to get used to the "Delete Array Element"...
Was Hänschen nicht lernt, lernt Hans nimmermehr! 😉