Note that there are some explanatory texts on larger screens.

plurals
  1. POSplit strings with an "Enter"
    text
    copied!<p>I have code that splits a string into 3 strings, then prints them. I want each one to be separated by the equivalent of an "Enter". Here's the code:</p> <pre><code>String accval = text; try { PrintWriter writer = new PrintWriter(new BufferedWriter( new FileWriter("sdcard/YS Data/Accelerometer.html", true))); String[] tempArr = accval.split("\\s+"); String x = tempArr[0] + "_"; //I want the enter to be where the underlines are: String y = tempArr[1] + "_"; String z = tempArr[2] + "_"; for (String a : tempArr) { writer.println("&lt;h3 style=padding-left:20px;&gt;" + x + y + z + "&lt;/h3&gt;&lt;br&gt;"); } writer.flush(); writer.close(); } catch (IOException e) { // put notification here later!!! e.printStackTrace(); } </code></pre> <p>This outputs:</p> <pre><code>x=-0.125_y=0.9375_z=0.375 x=-0.125_y=0.9375_z=0.375 </code></pre> <p>with the strings separated by underscores.</p> <p>However, I want it to look like this:</p> <pre><code>x=-0.125 y=0.9375 z=0.375 x=-0.125 y=0.9375 z=0.375 </code></pre> <p>Thanks for any help.</p> <p><em>EDIT:</em></p> <p>I've implemented the answer of @Julius in the following code that prints how I wanted it:</p> <p>Code:</p> <pre><code> String accval = text; try { PrintWriter writer = new PrintWriter(new BufferedWriter( new FileWriter("sdcard/YS Data/Accelerometer.html", true))); String[] tempArr = accval.split("\\s+"); String x = tempArr[0]; String y = tempArr[1]; String z = tempArr[2]; for (String a : tempArr) { writer.println("&lt;h3 style=padding-left:20px;&gt;" + x + "&lt;br&gt;" + y + &lt;br&gt; + z + "&lt;/h3&gt;&lt;br&gt;"); } writer.flush(); writer.close(); } catch (IOException e) { // put notification here later!!! e.printStackTrace(); } </code></pre> <p>Which prints:</p> <pre><code>x=0.25 y=125 z=1.23 x=0.125 y=725 z=0.935 </code></pre>
 

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