Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:11:46+00:00 2026-06-14T20:11:46+00:00

I have a for loop that adds items in an array to a listView.

  • 0

I have a for loop that adds items in an array to a listView.

(It’ll grab items on a webpage, remove anything after the ‘ in the string, then add it to the listView)

The error I am getting is: IndexOutOfRangeException was unhandled- Index was outside the bounds of the array

Here’s the code I am using:

string[] aa = getBetweenAll(vid, "<yt:statistics favoriteCount='0' viewCount='", "'/><yt:rating numDislikes='");
for (int i = 0; i < listView1.Items.Count; i++)
{
    string input = aa[i];
    int index = input.IndexOf("'");
    if (index > 0)
        input = input.Substring(0, index);
    listView1.Items[i].SubItems.Add(input);
}

The error occurs on this line: string input = aa[i];

Anything I did wrong? How can I fix this issue so it’ll stop happening? Thanks!

If you’re wondering the code for the getBetweenAll method is:

private string[] getBetweenAll(string strSource, string strStart, string strEnd)
{
    List<string> Matches = new List<string>();

    for (int pos = strSource.IndexOf(strStart, 0),
        end = pos >= 0 ? strSource.IndexOf(strEnd, pos) : -1;
        pos >= 0 && end >= 0;
        pos = strSource.IndexOf(strStart, end),
        end = pos >= 0 ? strSource.IndexOf(strEnd, pos) : -1)
    {
        Matches.Add(strSource.Substring(pos + strStart.Length, end - (pos + strStart.Length)));
    }

    return Matches.ToArray();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:11:47+00:00Added an answer on June 14, 2026 at 8:11 pm

    Your looping the elements of ‘listView1’

    If the item count of listView1 exceeds the number of elements of the string array ‘aa’ you will get this error.

    I would either change the loop to be

    for( ..., i < aa.Length, ...)
    

    or inside your for loop put an if statement to make sure that you are not exceeding the elements of aa. (although, I doubt this is what you want to do).

    for (int i = 0; i < listView1.Items.Count; i++)
    {
       if( i < aa.Length)
       {
          string input = aa[i];
          int index = input.IndexOf("'");
          if (index > 0)
             input = input.Substring(0, index);
          listView1.Items[i].SubItems.Add(input);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following loop that adds an object to an array if certain
I have a loop that adds an array of two values to a main
I have a loop that adds elements to a 1d array: for i in
I have a loop that goes through all the news items we have on
I have an inline assembler loop that cumulatively adds elements from an int32 data
hey, this i have a loop that adds gathered strings and ints into an
I have a while loop that adds elements read using a Buffered Reader to
I have some Javascript that dynamically adds rows/fields when you click the button, Add
I have a function that adds shopping cart data to an array of arrays.
I have a loop that enters each non-empty text field into a database: foreach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.