Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing decimals with a space at the end of a fixed-with string
    text
    copied!<p>Alright, so I have a working program that makes golden ratio rectangles based on a length or width given.</p> <p><img src="https://i.stack.imgur.com/Eh4WA.png" alt="Program Shown."> This probably isn't a good practice, but I wrote a <em>String.Slice(start, end)</em> in the extensions class.</p> <p><strong>Here's what I need help with.</strong></p> <pre><code> case 1: //Length l1.Text = value.ToString().Slice(0, 4); l2.Text = value.ToString().Slice(0, 4); h1.Text = (value/phi).ToString().Slice(0, 4); h2.Text = (value/phi).ToString().Slice(0, 4); break; case 2: //Width l1.Text = (value * phi).ToString().Slice(0, 4); l2.Text = (value * phi).ToString().Slice(0, 4); h1.Text = value.ToString().Slice(0, 4); h2.Text = value.ToString().Slice(0, 4); break; </code></pre> <p>Depending on the radiobutton, it finds the length or with based on what you provide. The problem is that with the strings all sliced to 1-4 characters, a number can be shown as </p> <pre><code> "161." </code></pre> <p>(with the period) in the textbox. Is there a way to make it so that only if it ends with a period that the period is removed? Thanks.</p> <p>P.S. Here's the slice function for reference: </p> <pre><code>public static class Extensions { public static string Slice(this string source, int start, int end) { if (end &lt; 0) // Keep this for negative end support { end = source.Length + end; } int len = end - start; // Calculate length try { return source.Substring(start, len); // Return Substring of length } catch (Exception) { try { return source.Substring(start, len - 1); // Return Substring of length } catch (Exception) { try { return source.Substring(start, len - 2); // Return Substring of length } catch (Exception) { return source.Substring(start, len - 3); // Return Substring of length } } } } } </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