Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing text in a file with datatable values
    primarykey
    data
    text
    <p>We have a sample text file with the text:</p> <blockquote> <p>The things God has prepared for those who love him</p> </blockquote> <p>We read the text into datatable and assigned some values like this:</p> <pre><code> The 1 ---------- things 2 ---------- God 3 ---------- has 4 ---------- prepared 5 ---------- for 6 ---------- those 7 ---------- who 8 ---------- love 9 ---------- him 10 ---------- </code></pre> <p>We're trying to replace the text in the input file with these corresponding numbers. Is it possible? If possible, how can we do it?</p> <p>Edit2: we edited our code like this:</p> <pre><code>: </code></pre> <p>void replace() {</p> <pre><code> 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[i1]; // exception occurs here // Console.WriteLine(ab); streamWriter.Write(ab.Replace(s1, s2)); i1++; } } streamReader.Close(); streamWriter.Close(); } </code></pre> <p>but we're getting an "Array index out of bounds" exception. we're unable to find the problem. thanks in advance</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