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 6659587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:03:05+00:00 2026-05-26T02:03:05+00:00

string cstring = e.Result; string[] delim = {<br>,*}; string[] cstringl = cstring.Split(delim, StringSplitOptions.None); for

  • 0
string cstring = e.Result;
            string[] delim = {"<br>","*"};
            string[] cstringl = cstring.Split(delim, StringSplitOptions.None);
            for (int i = 0; i < cstringl.Length; i++)
            {
                country_picker.Items.Add(cstringl[i]);
            }

I am using the above mentioned code to add items in a listbox named country picker, but i get indexoutofrange exception. Why am i getting this error when i have checked the length using i<=cstring1.Length

  • 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-05-26T02:03:06+00:00Added an answer on May 26, 2026 at 2:03 am

    I see 2 issues with your code.

    Update it as below:

    for (int i = 0; i < cstringl.Length; i++) 
    { 
        country_picker.Items.Add(cstringl[i]); 
    } 
    

    The 2 changes are:

    1. the comparision in the for loop to be “less than” the length, not “less than or equal to” as this will trigger an off by oe error due to Length being the count but the array being zero indexed. This is th cause of your IndexOutOfRangeException.

    2. Using the loop variable as an index reference when adding the item. So you don’t get the same (first) item added multiple times.

    Update
    Having looked at your code again, another possible issue could be caused by theinitial value of e.result. Try using StringSplitOptions.RemoveEmptyEntries so you don’t risk trygin to enter empty values. Also add a check that cstringl contains at least one item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CString is quite handy, while std::string is more compatible with STL container. I am
I have seen the following #include directives: #include <xstring> #include <cstring> #include <string> #include
I want to print the full length of a C-string in GDB. By default
I want to convert CString to string. (Yup. I know what am I doing.
Recently I made a utilities function like: // T2CA #include ATLCONV.H std::string Utils::CString2String(const CString&
Can CString::Format() receive const std::string? Example: void some_func( const std::string a_string ) { CString
The charset is Unicode. I want to write a string of CString type into
#include <iostream> #include <cstring> #include <string> template <typename T> inline T const& max (T
I have a C# string RIP-1234-STOP\0\0\0\b\0\0\0???|B?Mp?\0\0\0 returned from a call to a native driver.
I have a C# string object that contains the code of a generic method,

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.