Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo problems I can't solve when parsing the text how do i parse to the other way from right to left too?
    primarykey
    data
    text
    <p>This is the class that do the parsing:</p> <pre><code>public static string[] ParseText(string text, int startPos, int endPos) { List&lt;string&gt; parsedText = new List&lt;string&gt;(); string[] entries = null; if (startPos &gt;= 0 &amp;&amp; endPos &gt; startPos) { string images = text.Substring(startPos + 1, endPos - startPos - 1); entries = images.Split(new[] { ',' }); for (var i = 0; i &lt; entries.Length; i++) { entries[i] = entries[i].Replace("\"", ""); } for (int i = 0; i &lt; entries.Length; i++) { parsedText.Add(entries[i]); } } return entries; } </code></pre> <p>And in <code>Form1</code>:</p> <pre><code>private void richTextBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (mouseisup == false) { textBox1.Text = ""; positionToSearch = richTextBox1.GetCharIndexFromPosition(new Point(e.X, e.Y)); richTextBox1.SelectionStart = positionToSearch; textBox1.Text = richTextBox1.Text.Substring(positionToSearch, 1); previousChar = positionToSearch; textBox2.Text = ""; mouseisup = true; } else { currentChar = richTextBox1.GetCharIndexFromPosition(new Point(e.X, e.Y)); if (currentChar &gt; previousChar + 1)//currentChar &lt; previousChar - 1) { richTextBox1.SelectionStart = currentChar; textBox2.Text = richTextBox1.Text.Substring(currentChar, 1); button1.Enabled = true; } mouseisup = false; } } } private void richTextBox1_MouseUp(object sender, MouseEventArgs e) { if (textBox2.Text == "") { mouseisup = true; button1.Enabled = false; } } private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; string[] text = Parse_Text.ParseText(richTextBox1.Text, positionToSearch, currentChar); for (int i = 0; i &lt; text.Length; i++) { richTextBox2.Text = text[i]; } } </code></pre> <p>What it does now if I have a text in the richTextBox1 for example:</p> <pre><code>Daniel is greater &gt; the the smaller &lt; then &gt;&gt; higher is &lt; Daniel </code></pre> <p>So if I click first time on the first D then I click on the second D</p> <p>The text in richTextBox2 will be:</p> <pre><code>aniel is greater &gt; the the smaller &lt; then &gt;&gt; higher is &lt; </code></pre> <p>If I click on <code>i</code> and then on <code>&gt;</code></p> <p>So the text in richTextBox2 will be now:</p> <pre><code>s greater </code></pre> <p>Until this point everything is working good.</p> <p>The problem is when I click backward for example I click on the last D of Daniel And then i click on D of the first Daniel.</p> <p>Then im getting exception in the new class since :</p> <pre><code>if (startPos &gt;= 0 &amp;&amp; endPos &gt; startPos) </code></pre> <p>And then thevariable entries is null.</p> <p>How do i handle this case when i try to parse backward ? In Form1 i tried some thing but i check if textBox2 is empty and set the bool to true something here stuck me.</p> <pre><code>private void richTextBox1_MouseUp(object sender, MouseEventArgs e) { if (textBox2.Text == "") { mouseisup = true; button1.Enabled = false; } } </code></pre> <p>Since textBox2 is empty it will be always true. But i need to check if text is null the variable text is null then do something:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; string[] text = Parse_Text.ParseText(richTextBox1.Text, positionToSearch, currentChar); </code></pre> <p>If i check here if text is null and then textBox2 is empty then it will be true all the time the bool variable.</p> <p>Second problem is if I want to allow the user to parse from right to left ?</p> <p>If I mark the first D and the last D its ok.</p> <p>But if first i click on the last D and then the first D its returning null.</p> <p>So the two problems:</p> <ol> <li><p>How to handle the null entries variable if the code is as it is now? If it is null I want that the user will be start over again.</p></li> <li><p>If i want to change the code and allowed to parse from right to left ? What should I change in the new class code ?</p></li> </ol> <p>EDIT**</p> <pre><code>public static string[] ParseText(string text, int startPos, int endPos) { List&lt;string&gt; parsedText = new List&lt;string&gt;(); string[] entries = null; int tempPos = 0; if (startPos &gt; endPos) { tempPos = startPos; startPos = endPos; endPos = tempPos; } if (startPos &gt;= 0 &amp;&amp; endPos &gt; startPos) { string images = text.Substring(startPos + 1, endPos - startPos - 1); entries = images.Split(new[] { ',' }); for (var i = 0; i &lt; entries.Length; i++) { entries[i] = entries[i].Replace("\"", ""); } for (int i = 0; i &lt; entries.Length; i++) { parsedText.Add(entries[i]); } } return entries; } </code></pre> <p>This is the button click event:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; string[] text = Parse_Text.ParseText(richTextBox1.Text, positionToSearch, currentChar); for (int i = 0; i &lt; text.Length; i++) { richTextBox2.Text = text[i]; } } </code></pre>
    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