Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting integers to ASCII results in beeping and illegible text?
    primarykey
    data
    text
    <p>I've never encountered a problem like this in a console application - I hear some rather frightening beeping, the program (and my computer) freezes momentarily, and then the console just stops working - it doesn't even print an error message.</p> <p>I have <a href="http://projecteuler.net/project/cipher1.txt" rel="nofollow">this text file</a>. I read it as follows and then split the numbers into a list:</p> <pre><code>string path = @"C:\Users\owner\Documents\Quick Access\cipher1.txt"; string data = ""; using (StreamReader sr = new StreamReader(path)) { data = sr.ReadToEnd(); } List&lt;int&gt; encryptedNums = new List&lt;int&gt;(); foreach (string s in data.Split(',')) { encryptedNums.Add(Convert.ToInt32(s)); } </code></pre> <p>Each number represents an ASCII character. I want to concatenate these numbers into a string:</p> <pre><code>string encryptedString = ""; //WTF???? foreach (int n in encryptedNums) { encryptedString += (char)n; } </code></pre> <p>The <code>foreach</code> loop results in some very weird conversions. By printing out the characters one by one and comparing them with an <a href="http://www.asciitable.com/" rel="nofollow">ASCII table</a>, I see that the results are definitely <em>not</em> matching - for example, the number 2 results in a smiley-type figure. One of the conversions results in the beeping noise.</p> <p>Here's what really stymies me. I have a separate method where I do essentially the same thing - I have a list of integers and I try to convert them to a string:</p> <pre><code>string s = ""; foreach (int n in decrypted) { s += (char)n; } </code></pre> <p>But this actually results in a proper string! I don't see where my error is, and why the first conversion fails, while the second conversion (and unless I'm missing something, the code is the same) is fine. </p> <p>I'd appreciate any help.</p> <p>The code that ultimately causes is the crash is printing <code>encryptedString</code>.</p> <p><a href="http://pastebin.com/N4g64KWk" rel="nofollow">Here is the full code.</a></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.
 

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