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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:12:57+00:00 2026-05-29T06:12:57+00:00

we have a datatable st with two columns word and binary void replace() {

  • 0

we have a datatable “st” with two columns “word” and “binary”

void replace()
    {

        string s1="", s2="";            
        StreamReader streamReader;
        streamReader = File.OpenText("C:\\text.txt");
        StreamWriter streamWriter = File.CreateText("C:\\sample1.txt");
        int x = st.Rows.Count;
       // int i1 = 0;                                       
            // Now, read the entire file into a string
            while ((line = streamReader.ReadLine()) != null)
            {
                for (int i = 0; i < x; i++)
                {

                s1 = Convert.ToString(st.Rows[i]["Word"]);
                s2 = Convert.ToString(st.Rows[i]["Binary"]);
                s2+="000";
                char[] delimiterChars = { ' ', '\t' };
                String[] words = line.Split(delimiterChars);

                    // Write the modification into the same file                    
                String ab = words[i]; //exception occurs here
                // Console.WriteLine(ab);
                streamWriter.Write(ab.Replace(s1,s2));                                 
                }                
            }
        streamReader.Close();
        streamWriter.Close();
    }

we’re getting an “Index was outside the bounds of the array” exception. we’re unable to find the problem. thanks in advance

EDIT:
tnx to everyone who helped.
i did this and it worked somehow:

 void replace()
    {
        string s1 = "", s2 = "";
        StreamReader streamReader;
        streamReader = File.OpenText("C:\\sample1.txt");
        StreamWriter streamWriter = File.CreateText("C:\\sample1.txt");
        int x = st.Rows.Count;           
        while ((line = streamReader.ReadLine()) != null)
        {
            char[] delimiterChars = { ' ', '\t' };
            String[] words = line.Split(delimiterChars);
            foreach (string str in words)
            {

                s1 = str;
                DataRow drow = st.Rows.Find(str);
                if (drow != null)
                {
                    index = st.Rows.IndexOf(drow);
                    s2 = Convert.ToString(st.Rows[index]["Binary"]);
                  // s2 += "000";
                    // ab = words[i];                        
                    Console.WriteLine(s1);
                    Console.WriteLine(s2);
                    streamWriter.Write(str.Replace(s1, s2));                                 
                }
                else
                    break;
            }               
        }
        streamReader.Close();
        streamWriter.Close();
    }

tnx to everyone once again.
regards,
sagar

  • 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-29T06:12:58+00:00Added an answer on May 29, 2026 at 6:12 am

    If you have a hypothetical line “a b c d e” for instance the first line in your file, and your database “st” contains 10 rows, you would loop through the process 10 times, on the 6th time you would encounter the error. The 6th step would split the string into: {a, b, c, d, e} and then attempt to get the 5th index (zero based), which would be outside of the array.

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

Sidebar

Related Questions

I'm using Visual Studio 2005 and have a DataTable with two columns and some
I have two DataTables. First is DataTable NameAddressPhones = new DataTable(); with Three columns
I have datatable and there two column which is type of string and I
I have two datatable , first contain DataTable dtMaterialStatement = new DataTable(); dtMaterialStatement.Columns.Add(new DataColumn(MaterialNo,
I have a datatable containing 10 columns. I want to select only two columns
I have three columns in a datatable: string, DateTime, and decimal. I want to
I have a datatable with two columns. I want to store the rows of
Experts, I have a datatable with two columns: 1) One is Decimal 2) One
C# through ASP.Net 2.0. In a datatable I have two columns of IDs, attributeId
I have a task where I need to translate a DataTable to a two-dimensional

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.