Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting "Index was outside the bounds of the array" exception
    primarykey
    data
    text
    <p>we have a datatable "st" with two columns "word" and "binary"</p> <pre><code>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 &lt; 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(); } </code></pre> <p>we're getting an "Index was outside the bounds of the array" exception. we're unable to find the problem. thanks in advance</p> <p>EDIT: tnx to everyone who helped. i did this and it worked somehow:</p> <pre><code> 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(); } </code></pre> <p>tnx to everyone once again. regards, sagar</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload