2013-04-30

Quine Programming Assignment.

Originally Posted By: dtangster
While trying to do the Quine assignment I ran into a problem.

When I create a very large array of strings that contain my own code, I sometimes have to escape characters with a '\'. For example, when I need to add double quotes to my array of strings, I have to escape it. Now this causes a problem because when I print out the Quine, everything is correct EXCEPT for the lines that used escape characters because it doesn't show the extra '\'.

For example, an actual line of code in my program is:

System.out.println(self[STR_INDEX] + "\"" + self[i] + "\"" + ',');

For the array of strings that represent my code, one of the elements is this:

"System.out.println(self[STR_INDEX] + \"\\\"\" + self[i] + \"\\\"\" + ',');"

The problem now is that when I print this element back, it shows the element as being:

System.out.println(self[STR_INDEX] + "\"" + self[i] + "\"" + ',');

which is not the correct way I wrote it within the array of strings. I can't seem to get around this problem.
'''Originally Posted By: dtangster''' While trying to do the Quine assignment I ran into a problem.<br><br>When I create a very large array of strings that contain my own code, I sometimes have to escape characters with a '\'. For example, when I need to add double quotes to my array of strings, I have to escape it. Now this causes a problem because when I print out the Quine, everything is correct EXCEPT for the lines that used escape characters because it doesn't show the extra '\'.<br><br>For example, an actual line of code in my program is: <br><br>System.out.println(self[STR_INDEX] + &quot;\&quot;&quot; + self[i] + &quot;\&quot;&quot; + ',');<br><br>For the array of strings that represent my code, one of the elements is this: <br><br>&quot;System.out.println(self[STR_INDEX] + \&quot;\\\&quot;\&quot; + self[i] + \&quot;\\\&quot;\&quot; + ',');&quot;<br><br>The problem now is that when I print this element back, it shows the element as being:<br><br>System.out.println(self[STR_INDEX] + &quot;\&quot;&quot; + self[i] + &quot;\&quot;&quot; + ',');<br><br>which is not the correct way I wrote it within the array of strings. I can't seem to get around this problem.

-- Quine Programming Assignment
Originally Posted By: Jesse Evans
Code: public class Quine
{
  public static void main( String[] args )
  {
    char q = 34;      // Quotation mark character
    String[] l = {    // Array of source code


The above snippet is taken from the wikipedia article the prof posted. Any character in Java can be written as it's unicode code point to prevent this endless recursive escaping.

It is used in this line

Code: for( int i = 0; i

Here each line of the string array is printed so with the char q representing quotation marks.
http://www.fileformat.info/info/unicode ... /index.htm
'''Originally Posted By: Jesse Evans''' Code: public class Quine<br>{<br>&nbsp; public static void main( String[] args )<br>&nbsp; {<br>&nbsp; &nbsp; char q = 34;&nbsp; &nbsp; &nbsp; // Quotation mark character<br>&nbsp; &nbsp; String[] l = {&nbsp; &nbsp; // Array of source code<br><br><br>The above snippet is taken from the wikipedia article the prof posted. Any character in Java can be written as it's unicode code point to prevent this endless recursive escaping.<br><br>It is used in this line<br><br>Code: for( int i = 0; i <br><br>Here each line of the string array is printed so with the char q representing quotation marks.<br>http://www.fileformat.info/info/unicode ... /index.htm

-- Quine Programming Assignment
Originally Posted By: dtangster
Thanks! Got it working.
'''Originally Posted By: dtangster''' Thanks! Got it working.
X