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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:28:30+00:00 2026-06-15T20:28:30+00:00

I’m attempting to make a simple realtime search using a streamreader to read from

  • 0

I’m attempting to make a simple realtime search using a streamreader to read from a txt file and search and display the results in a listview, problem is I can only search for 1 letter, so searching for “1” will show me results for everything starting with 1, example search 1 results in “123”, but searching for “12” or “123” wont show the same result. Easier explained with this code I’ve tried.

Edit, text-file I’m reading from has this structure:
123;asd;asd;asd;asd;asd;asd <- example of a row

    public static string[] testtt(string sökord)
    {
        StreamReader asd = new StreamReader("film.txt");
        string temp;
        string[] xd;

        while (asd.Peek() >= 0) // if I can read another row (I.E next row isnt empty)
        {
            temp = asd.ReadLine();
            xd = temp.Split(';');

            for (int i = 0; i < xd.Length; i++)
            {
                // this should check if my searchword is equal to any member of "xd"
                // but this is where the problem occurs when the input is more than 1
                // character, will post error message from debugger below this code.
                if (xd[i].Substring(0, sökord.Length).ToLower() == sökord.ToLower())
                    return xd;
            }
        }

        return null;
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        try
        {
            listView1.Items.Clear();
            ListViewItem item = new ListViewItem(testtt(textBox1.Text)[0]);
            item.SubItems.Add(testtt(textBox1.Text)[1]);
            item.SubItems.Add(testtt(textBox1.Text)[2]);
            item.SubItems.Add(testtt(textBox1.Text)[3]);
            item.SubItems.Add(testtt(textBox1.Text)[4]);
            item.SubItems.Add(testtt(textBox1.Text)[5]);
            item.SubItems.Add(testtt(textBox1.Text)[6]);
            listView1.Items.Add(item);

            if (textBox1.Text == "")
                listView1.Items.Clear();
        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message);
        }
    }

ex

{"Index and length must refer to a location within the string.\r\nParameter name: length"} System.Exception {System.ArgumentOutOfRangeException}
  • 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-15T20:28:31+00:00Added an answer on June 15, 2026 at 8:28 pm

    This is fairly simple. This error will always appear when the line you have read form the stream reader, and you split and store the value in xd. Say the length of xd is n. And the sokord string you entered has say m length. Now when you write:
    (xd[i].Substring(0, sökord.Length)
    whenever the length of xd that is n is less than m, the Substring function would be trying to make a substring of m letters from only n letters. And hence it gives the error you mentioned.

    In any case just a simple check should do ok:

        String sString = null;
        if(xd[i].length>=sokord.length){
            sString = xd[i].SubString(0,sokord.length).toLower();
            if(sString.equals(sokord.toLower()))
                return xd;
        }
    

    Digvijay

    PS: To be honest I have written the answer from what best I could understand of what is trying to be done, so the code might be a little offtrack in one scenario. But in any case the error i have described above is 100% correct. So it would be best if you just look into that and follow the track. =)

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

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have just tried to save a simple *.rtf file with some websites and
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
i want to parse a xhtml file and display in UITableView. what is the
I'm making a simple page using Google Maps API 3. My first. One marker
I am using jsonparser to parse data and images obtained from json response. When
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.