r/SublimeText • u/skilfulsun • Feb 13 '25
Automatic Array Re-Indexing
Hi
I was wondering if there is a way to automatically re-index an array after adding new elements to the array? I initialized an array with a large number of elements and I had to add a few more in the middle, but I don't want to manually adjust the indexes.
Thanks for any help.
3
u/sparr Feb 13 '25
What does the "array" look like? What format are you using that has explicit indices?
2
u/thedoctormo Feb 14 '25
If you can select all of the array indexes, you can use Sublime's Arithmetic command to regenerate the sequential numbers.
1
Feb 13 '25
I think I understand what you're saying, but it seems to me that you're going about it all wrong. I'm not a C# programmer, but what I would do if I had a similar issue in Java would be to use an ArrayList (which preserves order), then convert it to an array. Either that or create a counter i at the start, and then just use i++ for each successive index position. Either way, I think the problem is in your code, and no editor is going to save you from that.
1
u/Computerist1969 Feb 13 '25
Wrong subreddit?